Cod sursa(job #3248573)
Utilizator | Data | 12 octombrie 2024 10:40:04 | |
---|---|---|---|
Problema | Sortare topologica | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m;
vector<set<int> > v;
vector<int> b;
void dfs(int i)
{
fout<<i<<" ";
b[i]=1;
for (set<int>::iterator it=v[i].begin(); it!=v[i].end(); it++){
if (!b[*it])dfs(*it);
}
}
int main()
{
fin>>n>>m;
v.resize(n+1);
b.resize(n+1);
for (int i=0; i<m; i++){
int x, y;
fin>>x>>y;
v[x].insert(y);
}
for (int i=1; i<=n; i++){
if (!b[i]){dfs(i);}
}
return 0;
}