Pagini recente » Diferente pentru home intre reviziile 645 si 644 | Monitorul de evaluare | Cod sursa (job #1749797) | Monitorul de evaluare | Cod sursa (job #2164996)
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
const int nmax = 50005;
vector < int > Muchii[nmax];
list < int > sol;
int n, m, x, y;
bool viz[nmax];
void DFS (int Nod) {
sol.push_back(Nod);
viz[Nod]=true;
for(unsigned i=0; i<Muchii[Nod].size(); i++) {
int v = Muchii[Nod][i];
if(!viz[v]) DFS(v);
}
}
int main()
{
fin >> n >> m;
for(int i=1; i<=m; i++) {
fin >> x >> y;
Muchii[x].push_back(y);
}
DFS(1);
while ( !sol.empty() ) {
fout << sol.front() << ' ' ;
sol.pop_front();
}
return 0;
}