Cod sursa(job #3241814)
| Utilizator | Data | 4 septembrie 2024 12:49:50 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m;
const int sz = 50000;
vector <int> v[sz + 5];
bool viz[sz + 5];
vector <int> stk;
void top(int nod)
{
viz[nod]=true;
for(auto& i : v[nod]) if(!viz[i]) top(i);
stk.push_back(nod);
}
int main()
{
fin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y;
fin>>x>>y;
v[x].push_back(y);
}
top(1);
reverse(stk.begin(),stk.end());
for(auto& i : stk) fout<<i<<' ';
}
