QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875314 | #9983. Color-Balanced Tree | ucup-team5008# | WA | 29ms | 3840kb | C++20 | 1.1kb | 2025-01-29 15:48:36 | 2025-01-29 15:48:36 |
Judging History
answer
#include <cstdio>
#include <vector>
const int N = 200000;
int n, t, c[N];
std::vector<int> g[N];
int dep[N], cnt[N];
void dfs(int v, int pr = -1) {
++cnt[dep[v]];
for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i] != pr) {
dep[g[v][i]] = dep[v] + 1;
c[g[v][i]] = !c[v];
dfs(g[v][i], v);
}
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i < 2 * n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
--a;
--b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(0);
int bal = 0;
for (int i = 0; i < 2 * n; ++i) {
if (i & 1) bal += cnt[i];
else bal -= cnt[i];
}
int start;
if (bal > 0) start = 1;
else {
start = 0;
bal = -bal;
}
int mx = 0, ind = 0;
for (int i = start; i < 2 * n; i += 2) {
if (cnt[i] > mx) {
mx = cnt[i];
ind = i;
}
}
for (int i = 0; i < 2 * n; ++i) if (dep[i] == ind && bal) {
bal -= 2;
c[i] = !c[i];
}
for (int i = 0; i < 2 * n; ++i) {
printf("%d ", c[i]);
c[i] = 0;
dep[i] = 0;
cnt[i] = 0;
g[i].clear();
}
printf("\n");
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
4 3 1 2 2 3 2 4 4 5 4 6 3 1 2 1 3 1 4 1 5 1 6 4 1 2 2 3 3 4 4 5 5 6 6 7 7 8 5 1 2 1 4 4 3 4 5 5 6 5 8 8 7 8 9 9 10
output:
0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
result:
ok correct! (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 29ms
memory: 3840kb
input:
10000 10 3 1 14 11 17 14 18 12 2 5 9 1 5 19 9 18 13 4 4 6 15 6 2 8 8 20 3 11 7 13 12 10 7 10 20 16 19 17 4 8 4 1 5 5 3 8 2 6 4 2 7 5 4 1 2 1 2 3 2 2 4 4 1 5 4 5 8 1 3 9 10 2 7 2 8 6 6 9 4 7 3 10 3 1 4 6 5 4 3 5 3 2 6 6 12 10 7 6 11 7 5 11 8 11 2 7 4 1 3 10 4 2 9 4 2 10 12 19 6 8 15 16 18 1 18 18 12 ...
output:
0 1 1 1 0 0 1 0 1 0 0 1 0 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 1 0 0 0 1 0...
result:
wrong answer diff > 3 (test case 39)