Pagini recente » Cod sursa (job #820752) | Cod sursa (job #2662131) | Cod sursa (job #2914486) | Cod sursa (job #641094) | Cod sursa (job #2933473)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
vector<vector<int> > theNeighbours;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int> solution;
bool found[100005];
void dfs(int node){
found[node] = true;
for(int i = 0; i < theNeighbours[node].size(); i++)
{
int newNode = theNeighbours[node][i];
if(found[newNode] == false){
dfs(newNode);
}
}
solution.push_back(node);
}
int main()
{
int n, m;
cin>>n>>m;
theNeighbours = vector<vector<int> > (n + 5);
for(int i = 0; i < m; i++){
int firstNode, secondNode;
cin>>firstNode>>secondNode;
theNeighbours[firstNode].push_back(secondNode);
}
for(int i = 1; i <= n; i++){
if(found[i] == false) dfs(i);
}
for(int i = solution.size() - 1; i >= 0; i--){
cout<<solution[i]<<" ";
}
return 0;
}