Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- using pi32 = pair<int, int>;
- using pi64 = pair<int64_t, int64_t>;
- using ti32 = tuple<int, int, int>;
- using ti64 = tuple<int64_t, int64_t, int64_t>;
- const int N = 1e5 + 5;
- int n, nE;
- vector<pi32> graph[N];
- bool visited[4 * N];
- vector<int> path;
- void Euler(int u) {
- while (!graph[u].empty()) {
- const auto [v, id] = graph[u].back(); graph[u].pop_back();
- if (!visited[id]) {
- visited[id] = true;
- Euler(v);
- }
- }
- path.push_back(u);
- }
- int main() {
- #ifdef LOCAL
- freopen("in.txt", "r", stdin);
- #else
- freopen("CJANDDENISEi.inp", "r", stdin);
- freopen("CJANDDENISE.out", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n >> nE;
- for (int i = 1; i <= nE; i++) {
- int u, v; cin >> u >> v;
- graph[u].push_back({v, i});
- graph[v].push_back({u, i});
- }
- Euler(1);
- for (int u : path)
- cout << u << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment