-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilddeps.cpp
59 lines (51 loc) · 1.15 KB
/
builddeps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
unordered_map<string, vector<string>> AL;
unordered_map<string, int> visited;
stack<string> tps;
void dfs(string s) {
if (visited[s]) return;
visited[s] = true;
for (auto& x : AL[s]) {
if (!visited[x]) dfs(x);
}
tps.push(s);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("1.in","r",stdin);
int n; cin >> n; cin.get();
while (n--) {
string input, file, s;
getline(cin, input);
stringstream ss(input);
ss >> file; file = file.substr(0, file.length()-1);
while (ss >> s) {
AL[s].emplace_back(file);
}
}
string start; cin >> start;
dfs(start);
while (!tps.empty()) {
cout << tps.top() << endl; tps.pop();
}
}