QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#547899#7755. Game on a ForestCodeK_GWA 1ms5528kbC++171.4kb2024-09-05 12:39:592024-09-05 12:39:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-05 12:39:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5528kb
  • [2024-09-05 12:39:59]
  • 提交

answer

# include <bits/stdc++.h>

using namespace std;
const int N = 100010;
int n, m;
int h[N], e[N], ne[N], tag[N], num[N], sum[N], idx;

void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

int dfs(int u, int id)
{
	tag[u] = id;
	int d = 1;
	for(int i = h[u]; ~i; i = ne[i])
	{
		int j = e[i];
		d += dfs(j, id);
	}
	return num[u] = d;
}

int main()
{
	memset(h, -1, sizeof h);
	scanf("%d%d", &n, &m);
	while(m --)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b);
	}
	
	int id = 0;
	for(int i = 1; i <= n; i ++)
		if(!tag[i])
			dfs(i, ++ id);
	for(int i = 1; i <= n; i ++) sum[tag[i]] ++;
	
	int res = 0, odd = 0, even = 0;
	for(int i = 1; i <= n; i ++)
		if(sum[i])
		{
			if(sum[i] % 2) odd ++;
			else even ++;
		}
		else break;
		
	for(int i = 1; i <= n; i ++)
	{
		int t1 = odd, t2 = even;
		if(sum[tag[i]] % 2) t1 --;
		else t2 --;
		
		for(int j = h[i]; ~j; j = ne[j])
		{
			int u = e[j];
			
			int r1 = t1, r2 = t2;
			if(num[u] % 2) r1 ++;
			else r2 ++;
			
			if((sum[tag[i]] - num[u]) % 2) r1 ++;
			else r2 ++;
			if(r1 % 2 == 0 && r2 % 2 == 0) res ++;
		}
		
		for(int j = h[i]; ~j; j = ne[j])
		{
			int u = e[j];
			if(num[u] % 2) t1 ++;
			else t2 ++;
		}
		if((sum[tag[i]] - num[i]) % 2) t1 ++;
		else t2 ++;
		if(t1 % 2 == 0 && t2 % 2 == 0) res ++;
	}
	printf("%d\n", res);
	return 0;
}
	
	
	

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4308kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 4264kb

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5464kb

input:

100000 1
4647 17816

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 5504kb

input:

100000 2
64075 72287
63658 66936

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5384kb

input:

100000 3
59930 72281
31689 59132
20469 33165

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5528kb

input:

100000 10
20391 78923
27822 80617
21749 25732
12929 79693
42889 52515
59064 99869
29031 41875
4463 17813
13407 42498
19120 20957

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 5484kb

input:

99999 101
34378 94161
67696 83255
24557 25591
11476 58475
5684 38157
33843 35321
9046 24028
14293 77681
587 42098
9402 27228
6999 13980
27118 84005
3622 8353
13545 51621
16998 63647
32912 53178
15206 15815
56517 86335
5563 93770
153 278
11242 41753
75098 76792
1695 22836
25936 33352
2765 6778
19597 ...

output:

99898

result:

wrong answer 1st numbers differ - expected: '200', found: '99898'