Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("competitie.in");
- ofstream fout("competitie.out");
- int n, m, a[1005][1005], x, y, viz[1005], postordine[1005], nr;
- void DFS(int x)
- {
- int i;
- viz[x]=1;
- for(i=1;i<=a[x][0];i++)
- if(!viz[a[x][i]])
- DFS(a[x][i]);
- postordine[++nr]=x;
- }
- int main()
- {
- int i;
- fin>>n>>m;
- for(i=0;i<m;i++)
- {
- fin>>x>>y;
- a[x][0]++;
- a[x][a[x][0]]=y;
- }
- for(i=n;i>0;i--)
- if(!viz[i])
- DFS(i);
- for(i=n;i>0;i--)
- fout<<postordine[i]<<" ";
- return 0;
- }
Add Comment
Please, Sign In to add comment