Cod sursa(job #2807052)
| Utilizator | Data | 23 noiembrie 2021 12:31:02 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n,m,x,y;
bool vis[50005];
vector <int> g[50005],sol;
void dfs(int u)
{
sol.push_back(u);
vis[u]=1;
for(auto v:g[u])
if(vis[v]==0)
dfs(v);
}
int main()
{
fin>>n>>m;
for(int i=1; i<=m; i++)
{
fin>>x>>y;
g[x].push_back(y);
}
dfs(1);
for(int x:sol)
fout<<x<<" ";
fout<<"\n";
return 0;
}
