Cod sursa(job #1799609)

Utilizator bleo16783FMI Bleotiu Cristian bleo16783 Data 6 noiembrie 2016 16:01:44
Problema Sortare topologica Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<fstream>
#include<vector>
#define t 50001
using namespace std;int x,m,n,y,d[t],i;vector<int>a[t],v;bool w[t];void D(int x){w[x]=1;for(int i=0;i<d[x];){int y=a[x][i++];if(!w[y])D(y);}v.push_back(x);++m;}int main(){ifstream f("sortaret.in");f>>n>>m;for(;m--;)f>>x>>y,a[x].push_back(y);++m;i=n;for(;i;)d[i]=a[i--].size();for(;i<n;)if(!w[++i])D(i);ofstream g("sortaret.out");for(;m;)g<<v[--m]<<" ";}