QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#547900 | #7755. Game on a Forest | CodeK_G | WA | 1ms | 4356kb | C++17 | 1.4kb | 2024-09-05 12:42:13 | 2024-09-05 12:42:13 |
Judging History
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]] > 1)
{
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: 0
Wrong Answer
time: 1ms
memory: 4356kb
input:
3 1 1 2
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'