Pagini recente » Cod sursa (job #823055) | Cod sursa (job #2848215) | Cod sursa (job #165112) | Cod sursa (job #633806) | Cod sursa (job #2066682)
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
const int N = 50005;
const int M = 100005;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
int n,m;
bool parinte[N];
bool viz[N];
vector <int> V[N];
queue <int> q;
void dfs(int pc)
{
viz[pc] = 1;
q.push(pc);
for(int i = 0; i< V[pc].size(); i++)
{
int nx = V[pc][i];
if(viz[nx] == 0)
{
dfs(nx);
}
}
//g<<pc<<" ";
}
int main()
{
f>>n>>m;
for(int i = 1; i<= n; i++)
{
int x,y;
f>>x>>y;
V[x].push_back(y);
parinte[y] = 1;
}
for(int i = 1; i<= n; i++)
{
if(parinte[i] == 0)
{
dfs(i);
}
}
//g<<"\n\n";
while(!q.empty())
{
g<<q.front()<<" ";
q.pop();
}
f.close();
g.close();
return 0;
}