Pagini recente » Cod sursa (job #1238021) | Cod sursa (job #1393752) | Cod sursa (job #344726) | Cod sursa (job #719742) | Cod sursa (job #606581)
Cod sursa(job #606581)
# include <fstream>
# include <queue>
# include <vector>
using namespace std;
ifstream f ("sortaret.in");
ofstream g ("sortaret.out");
int n, m, x, y, ap[50010];
vector <int> A[50010];
queue <int> Q;
int main ()
{
f >> n >> m;
for (int i = 1; i <= m; ++i)
f >> x >> y, A[x].push_back (y), ++ap[y];
for (int i = 1; i <= n; ++i)
if (!ap[i]) Q.push (i), g << i << ' ';
for (; !Q.empty (); Q.pop ())
{
int ret = Q.front ();
for (vector <int> :: iterator it = A[ret].begin (); it != A[ret].end (); ++it)
if (ap[*it])
{
--ap[*it];
if (!ap[*it]) g << *it << ' ';
Q.push (*it);
}
}
g.close ();
return 0;
}