Cod sursa(job #1998680)

Utilizator dumitrescu_andreiDumitrescu Andrei dumitrescu_andrei Data 8 iulie 2017 18:54:37
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");

vector <int> V[50001];
int n,m;
bool viz[50001];

void DFS(int x)
{
    viz[x]=1;
    g<<x<<" ";
    for(int i=0;i<V[x].size();++i)
        if(!viz[V[x][i]])
           DFS(V[x][i]);

}

int main()
{
 f>>n>>m;
 for(int i=1;i<=m;++i)
{
    int x,y;
    f>>x>>y;
    V[x].push_back(y);
}

for(int i=1;i<=n;++i)
    if(!viz[i])
    DFS(i);
return 0;

}