Pagini recente » Autentificare | Cod sursa (job #2443213) | Cod sursa (job #2655720) | Istoria paginii runda/oji2007_clasele_11-12/clasament | Cod sursa (job #2425567)
#include <bits/stdc++.h>
using namespace std;
vector <int> VIZITAT(1000);
queue <int> RETURNEZ;
vector <int> cev[1000];
void dfs(int start){
VIZITAT[start] = true;
for(auto it: cev[start]){
if(!VIZITAT[it]){
dfs(it);
}
}
RETURNEZ.push(start);
}
int main()
{
ifstream fin("sortaret.in");
int noduri, muchii;
fin >> noduri >> muchii;
for(int i = 1; i <= muchii; i++){
int x, y;
fin >> x >> y;
cev[x].push_back(y);
}
for(int i = 1; i <= noduri; i++)
VIZITAT[i] = false;
dfs(1);
ofstream fout("sortare.out");
while(!RETURNEZ.empty()){
fout << RETURNEZ.front() << " ";
cout << RETURNEZ.front() << " ";
RETURNEZ.pop();
}
return 0;
}