Pagini recente » Cod sursa (job #499495) | Statistici Vlad Eugen Dornescu (dornescuvlad) | Cod sursa (job #396083) | Cod sursa (job #1745894) | Cod sursa (job #1732413)
#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);
}