欧拉回路
\(\color{CornflowerBlue}{【uoj\ 117】}\)
#include <cstdio>
const int N = 100005, M = 200005;
int head[N], nxt[M<<1], pnt[M<<1], tot = 1, in[N], out[N], vis[M], ans[M], cnt;
int read() {
int x = 0; char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x;
}
void add_edge(int u, int v) {
nxt[++tot] = head[u];
head[u] = tot, pnt[tot] = v;
}
void dfs(int cur) {
for (int &i = head[cur], j; i; i = nxt[i]) {
if (vis[(j=i)>>1]) continue;
vis[j>>1] = 1, dfs(pnt[j]), ans[++cnt] = j;
}
}
int main() {
int t = read(), n = read(), m = read();
for (int i = 1; i <= m; ++i) {
int u = read(), v = read();
add_edge(u, v);
if (t == 2) ++out[u], ++in[v], ++tot;
else add_edge(v, u), ++in[u], ++in[v];
}
if (t == 1) {
for (int i = 1; i <= n; ++i)
if (in[i] & 1) { puts("NO"); return 0; }
} else {
for (int i = 1; i <= n; ++i)
if (in[i] != out[i]) { puts("NO"); return 0; }
}
dfs(pnt[2]);
if (cnt < m) puts("NO");
else {
puts("YES");
for (int i = cnt; i; --i)
printf("%d ", (ans[i] >> 1) * (ans[i] & 1 ? -1 : 1));
}
return 0;
}