QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875303#9983. Color-Balanced Treeucup-team5008#WA 0ms3840kbC++20586b2025-01-29 15:28:232025-01-29 15:28:28

Judging History

This is the latest submission verdict.

  • [2025-01-29 15:28:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3840kb
  • [2025-01-29 15:28:23]
  • Submitted

answer

#include <cstdio>
#include <vector>

const int N = 200000;
int n, t;
std::vector<int> g[N];
int c[N];

void dfs(int v, int pr = -1) {
	for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i] != pr) {
		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);
		for (int i = 0; i < 2 * n; ++i) {
			printf("%d ", c[i]);
			c[i] = 0;
			g[i].clear();
		}
		printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
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 1 1 1 1 1 
0 1 0 1 0 1 0 1 
0 1 0 1 0 1 0 1 0 1 

result:

wrong answer The number of black vertices and red vertices are not equal (test case 2)