voidwork() { std::cin >> n; for (int i = 1; i <= n; ++ i) scanf("%d", a + i); for (int i = 1; i <= n; ++ i) scanf("%d", b + i); for (int i = 1; i <= n; ++ i) nw[a[i]] = i; for (int i = 1; i <= n; ++ i) bel[i] = 0; int cnt = 0; for (int i = 1; i <= n; ++ i) { if (bel[i] || a[i] == b[i]) continue; ++ cnt; int j = i; while (!bel[j]) bel[j] = cnt, j = nw[b[j]]; } for (int i = 1; i <= cnt; ++ i) usd[i] = false; for (int i = 1, x; i <= n; ++ i) { scanf("%d", &x); if (x) usd[bel[i]] = true; } int und = 0; for (int i = 1; i <= cnt; ++ i) und += !usd[i]; printf("%d\n", pw2[und]); }
voiddfs(int x, int fa, int ex) { for (int i = h[x]; ~i; i = ne[i]) { if (e[i] == fa) continue; ++ tot; w[i] = w[i ^ 1] = tot ^ (ex * n), val[e[i]] = tot ^ (!ex * n); dfs(e[i], x, !ex); } } voidwork() { std::cin >> n, n = 1 << n, tot = 0; for (int i = 1; i <= n; ++ i) h[i] = -1; idx = 0; for (int i = 1, u, v; i < n; ++ i) { scanf("%d %d", &u, &v); add(u, v), add(v, u); } val[1] = n, dfs(1, 0, 1); puts("1"); for (int i = 1; i <= n; ++ i) printf("%d ", val[i]); puts(""); for (int i = 0; i < idx; i += 2) printf("%d ", w[i]); puts(""); }