Pagini recente » Cod sursa (job #1005270) | Cod sursa (job #613952) | Cod sursa (job #2795511) | Cod sursa (job #1673768) | Cod sursa (job #2066694)
#include <fstream>
#include <stack>
#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];
stack <int> q;
void dfs(int pc)
{
viz[pc] = 1;
for(int i = 0; i< (int)V[pc].size(); i++)
{
int nx = V[pc][i];
if(viz[nx] == 0)
{
dfs(nx);
}
}
q.push(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.top()<<" ";
q.pop();
}
f.close();
g.close();
return 0;
}