File tree 1 file changed +8
-13
lines changed
1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -3,47 +3,42 @@ using namespace std;
3
3
4
4
#define rep (i,a,b ) for (int i = a ; i < b ; i++)
5
5
6
- void IO ()
7
- {
8
- freopen ( " in.txt" , " r" ,stdin);
9
- }
10
-
11
- const int N = 109 ;
12
-
6
+ const int N = 100007 ;
13
7
std::vector<int > graph[N];
14
8
bool vis[N];
15
9
16
10
stack<int > ans;
17
11
18
12
void dfs (int source){
19
13
vis[source] = 1 ;
20
-
14
+
21
15
for (auto child:graph[source]){
22
16
if (!vis[child]) dfs (child);
23
17
}
24
-
25
18
ans.push (source); // when all the childs of a node have been visited then we will push it into the stack
26
19
}
27
20
28
21
void solve (int t){
29
- int n,m ; cin >> n >> m ;
22
+ int node,edge ; cin >> node >> edge ;
30
23
31
24
rep (i,0 ,m){
32
25
int u , v;
33
26
cin >> u >> v;
34
27
graph[u].push_back (v); // directed graph
35
28
}
36
29
37
- rep (i,1 ,n+1 ) if (!vis[i]) dfs (i);
30
+ rep (i,1 ,node+1 )
31
+ if (!vis[i])
32
+ dfs (i);
38
33
39
34
while (!ans.empty ()){
40
35
cout << ans.top () << ' ' ; ans.pop ();
41
36
}
37
+ cout << ' \n ' ;
42
38
}
43
39
44
40
int32_t main ()
45
- {
46
- IO ();
41
+ {
47
42
int t = 1 ;
48
43
// cin >> t;
49
44
You can’t perform that action at this time.
0 commit comments