constint N = 1e5+10, M = 4e5+10; int type, n, m; int h[N], e[M], ne[M], din[N], dout[N], idx; bool used[M]; int ans[N*2], cnt;
voidadd(int a, int b){ e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
boolcheck(){ for (int i = 1; i <= n; i++) if (type == 1) { if (din[i] + dout[i] & 1) returnfalse; } elseif (din[i] != dout[i]) { returnfalse; } returntrue; }
voiddfs(int u){ // 表头是不断往下移动的,而 ne 是不变的 // 如果写 i=ne[i] 遇到自环就被卡了 for (int i = h[u]; ~i; i = h[u]) { h[u] = ne[i]; if (used[i]) { continue; } used[i] = true; // 这句不加也行 强迫症 if (type == 1) used[i^1] = true; dfs(e[i]); if (type == 1) { // (0, 1) -> 1 // (2, 3) -> 2 // (4, 5) -> 3 int t = i/2 + 1; if (i & 1) t = -t; ans[cnt++] = t; } else ans[cnt++] = i+1; } }
intmain(){ cin >> type >> n >> m; memset(h, -1, sizeof h); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; add(a, b); if (type == 1) add(b, a); dout[a]++, din[b]++; } if (!check()) { cout << "NO\n"; return0; } // 随便找一个能向下走的点开始 因为每个点不一定都用上了 for (int i = 1; i <= n; i++) if (~h[i]) { dfs(i); break; } if (cnt < m) { cout << "NO\n"; return0; } cout << "YES\n"; for (int i = cnt-1; i >= 0; i--) cout << ans[i] << ' '; cout << '\n'; return0; }