Pagini recente » Istoria paginii runda/testround2 | Autentificare | Probleme de Taietura | Cod sursa (job #2510588) | Cod sursa (job #2476540)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
const int Nmax = 5e4 + 5;
vector <int> a[Nmax];
vector <int>::iterator it;
int q[Nmax];
int g[Nmax];
int N,M;
int main()
{
in >> N >> M;
while(M--)
{
int x,y;
in >> x >> y;
a[x].push_back(y);
g[y]++;
}
for(int i = 1; i <= N; ++i)
if(!g[i])
q[++q[0]] = i;
for(int i = 1; i <= N; ++i)
{
int x = q[i];
for(it = a[x].begin(); it != a[x].end(); ++it)
{
g[*it]--;
if(!g[*it])
q[++q[0]] = *it;
}
}
for(int i = 1; i <= N; ++i)
out << q[i] << " ";
return 0;
}