Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Statistici Alistar Andrei (AndrewA) | Cod sursa (job #688032) | Cod sursa (job #2050897)
#include <fstream>
#include <vector>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
vector <int> l[100005],z;
bool viz[50005],ok;
int k,u,p,poz,n,s,m,x,y,nr;
void topo(int nod)
{
int i;
viz[nod] = 1;
for(i = 0; i< l[nod].size(); i++)
if(viz[l[nod][i]] == 0)
{
z.push_back(l[nod][i]);
topo(l[nod][i]);
}
}
int main()
{
f>>n>>m;
for(int i = 1; i<= m; i++)
{
f>>x>>y;
ok=1;
for(int j = 0; j < l[x].size() && ok; j++)
if(l[x][y] == y)
ok = 0;
if(ok)
l[x].push_back(y);
}
z.push_back(1);
for(int i=1;i<=n;i++)
if(viz[i]==0)
topo(i);
for(int i=1;i<z.size();i++)
g<<z[i]<<' ';
return 0;
}