Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- #include <vector>
- #include <algorithm>
- using namespace std;
- #define si(a) scanf("%d",&a)
- #define f first
- #define s second
- #define mp(a,b) make_pair(a,b)
- #define MAX 1005
- int vis[MAX];
- vector<int> graph[MAX];
- vector<int> sorted_ara;
- void go(int now)
- {
- if(vis[now])
- return ;
- vis[now]=1;
- for(int i=0;i<graph[now].size();i++)
- go(graph[now][i]);
- sorted_ara.push_back(now);
- }
- int main()
- {
- //freopen("input","r",stdin);
- int n,m,i;
- si(n);si(m);
- for(i=0;i<m;i++){
- int u,v;
- si(u);si(v);
- u--;v--;
- graph[u].push_back(v);
- }
- for(i=0;i<n;i++)
- go(i);
- reverse(sorted_ara.begin(),sorted_ara.end());
- for(i=0;i<n;i++)
- cout<<sorted_ara[i]+1<<" ";
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement