-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10305.cpp
More file actions
48 lines (44 loc) · 907 Bytes
/
Copy path10305.cpp
File metadata and controls
48 lines (44 loc) · 907 Bytes
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
#include <iostream>
#include <cstdio>
#include <vector>
#define foi( i , n , k ) for( int i = n ; i < k ; ++i )
using namespace std;
void dfs( vector< vector<int> > &graph,vector<int>&res,vector<bool> &pas,int node)
{
if( pas[node] )
return;
pas[node]=true;
foi( i , 0 , graph[node].size() )
{
dfs(graph,res,pas,graph[node][i]);
}
res.push_back(node);
}
int main()
{
int n,v;
while( scanf("%d%d",&n,&v)!=EOF && (n||v) )
{
vector< vector<int> > graph(n,vector<int>());
vector< bool > pas(n,false);
foi( i , 0, v )
{
int a,b;
scanf("%d%d",&a,&b);
--a;
--b;
graph[a].push_back(b);
}
vector<int> res;
foi( i , 0 , n )
dfs(graph,res,pas,i);
for( int i = res.size()-1 ; i >= 0 ; --i )
{
if( i!= res.size()-1)
printf(" ");
printf("%d",res[i]+1);
}
printf("\n");
}
return 0;
}