Pagini recente » Cod sursa (job #1671270) | Cod sursa (job #3038422) | Cod sursa (job #2300383) | Cod sursa (job #1437606) | Cod sursa (job #3267911)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
struct node {
unordered_multiset<int> in;
unordered_multiset<int> out;
};
array<node,100001> g;
vector<int> ans;
void solve(int x) {
node& nodeX = g[x];
while (!nodeX.out.empty()) {
int y = *nodeX.out.begin();
nodeX.out.erase(nodeX.out.find(y));
node& nodeY = g[y];
nodeY.in.erase(nodeY.in.find(x));
solve(y);
}
ans.push_back(x);
}
int n,m;
int main() {
fin >> n >> m;
for (int i = 1; i <= m; i++) {
int x,y;
fin >> x >> y;
g[x].out.insert(y);
g[y].in.insert(x);
}
solve(1);
for (auto it = ans.rbegin(); it != ans.rend(); it++) {
fout << *it << ' ';
}
return 0;
}