Pagini recente » Cod sursa (job #1267711) | Cod sursa (job #2520755) | Cod sursa (job #873486) | Cod sursa (job #274102) | Cod sursa (job #3268019)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in");
ofstream fout("ciclueuler.out");
struct node {
unordered_map<int,int> in;
unordered_map<int,int> out;
};
array<node,500001> g;
vector<int> ans;
void solve(int x) {
node& nodeX = g[x];
while (!nodeX.out.empty()) {
int y = nodeX.out.begin()->first;
nodeX.out[y]--;
if (!nodeX.out[y])
nodeX.out.erase(nodeX.out.find(y));
node& nodeY = g[y];
nodeY.in[x]--;
if (!nodeY.in[x])
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[y]++;
g[y].in[x]++;
}
solve(1);
for (auto it = ans.rbegin(); it != ans.rend(); it++) {
fout << *it << ' ';
}
return 0;
}