voiddfs(int u){ for (int &i = hd[u]; i > 0; i = nxt[i]) { if (vis[i / 2]) { continue; } vis[i / 2] = true; int tmp = i % 2 == 1 ? -(i / 2) : i / 2; dfs(to[i]); p.push_back(tmp); } }
voidproc(){ for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; ae(u, v); } int s = 0; for (int i = 1; i <= n; ++i) { if (d[i] % 2 == 1) { cout << "NO\n"; return; } if (d[i] > 0) { s = i; } } if (s != 0) { dfs(s); } if (len(p) < m) { cout << "NO\n"; return; } cout << "YES\n"; for (int i = m; --i >= 0;) { cout << p[i] << " \n"[i == 0]; } } }
namespace directed { constexprint N = 1e5 + 5, M = 2e5 + 5;
int tot, hd[N], nxt[M], to[M], inD[N], outD[N]; vector<int> p;
voidae(int u, int v){ ++inD[v], ++outD[u]; nxt[++tot] = hd[u], hd[u] = tot, to[tot] = v; }
voiddfs(int u){ int &i = hd[u]; while (i > 0) { int tmp = i; i = nxt[i]; dfs(to[tmp]); p.push_back(tmp); } }
voidproc(){ for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; ae(u, v); } int s = 0; for (int i = 1; i <= n; ++i) { if (inD[i] != outD[i]) { cout << "NO\n"; return; } if (inD[i] > 0) { s = i; } } if (s != 0) { dfs(s); } if (len(p) < m) { cout << "NO\n"; return; } cout << "YES\n"; for (int i = m; --i >= 0;) { cout << p[i] << " \n"[i == 0]; } } }