Cod sursa(job #1732413)

Utilizator topala.andreiTopala Andrei topala.andrei Data 21 iulie 2016 16:31:14
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
const int maxn=50001;
vector <int> a[maxn];
int N,M,verif[maxn];
void topo(int x)
{
    verif[x]=1;
    for (int i=0;i<a[x].size();i++)
        if (verif[a[x][i]]==0) topo(a[x][i]);
    g<<x;
}
int main()
{
    int i,x,y;
    f>>N>>M;
    for (i=1;i<=M;i++)
    {
        f>>x>>y;
        a[y].push_back(x);
    }
    for (i=1;i<=N;i++)
        if (verif[i]==0) topo(i);
}