Pagini recente » Cod sursa (job #2058226) | Cod sursa (job #2083733) | Cod sursa (job #263166) | Cod sursa (job #1144951) | Cod sursa (job #1543137)
#include <iostream>
#include<vector>
#include<fstream>
#include<queue>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int MAXN=50001;
vector <int> Graf[MAXN];
queue <int> Q;
int In[MAXN],Out[MAXN];
using namespace std;
int n,m;
int main()
{
fin>>n>>m;
for(int i=0;i<=m;i++)
{
int x,y;
fin>>x>>y;
Graf[x].push_back(y);
// In[y]++;
Out[y]++;
}
for(int i=1;i<=n;i++)
{
if(Out[i]==0)
{
Q.push(i);
fout<<i<<" ";
}
}
while(!Q.empty())
{
int nod=Q.front();
Q.pop();
for(int i=0;i<Graf[nod].size();i++)
{
int act_nod=Graf[nod][i];
Out[act_nod]--;
if(Out[act_nod]==0)
{
Q.push(act_nod);
fout<<act_nod<<" ";
}
}
}
}