QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269958 | #7755. Game on a Forest | time_interspace# | WA | 1ms | 6420kb | C++20 | 1.4kb | 2023-11-30 12:20:49 | 2023-11-30 12:20:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j; i <= k; ++i)
#define repp(i,j,k) for(int i = j; i >= k;--i)
#define ll long long
int cnt[2];
int n,m,rt;
vector<int>E[101000];
bool vis[101000];
int bel[101000],sz[101000],fa[101000];
int rd() {
int x; scanf("%d",&x);
return x;
}
void dfs(int x) {
bel[x] = rt; sz[x]++;
vis[x] = true;
for(auto y:E[x]) if(!vis[y]){
fa[y] = x; dfs(y);
sz[x] += sz[y];
}
}
int ans = 0;
int f[2];
void solve(int x) {
f[1] = cnt[1]&1; f[0] = cnt[0]&1;
if( x != rt ) {
f[ sz[x]&1 ] ^= 1;
f[ (sz[rt]-sz[x])&1 ] ^= 1;
if( (f[1]==0&&f[0]==0) ) ans++;//,printf("*%d %d\n",x,fa[x]);
}
f[1] = cnt[1]&1; f[0] = cnt[0]&1;
if( x != rt ) f[ (sz[rt]-sz[x])&1 ] ^= 1;
for(auto y:E[x] ) if(y != fa[x]) f[ sz[y]&1 ] ^= 1;
// if( x == 2 ) printf("###%d %d\n",f[0],f[1]);
if( (f[1]==0&&f[0]==0) ) ans++;//,printf("#%d\n",x);
for(auto y:E[x] ) if(y != fa[x]) solve(y);
}
void work() {
rep(x,1,n) if( bel[x] == x ) {
rt = x;
cnt[sz[x]%2]--;
// printf("*%d sz:%d %d %d\n",x,sz[x],cnt[0],cnt[1]);
solve(x);
cnt[sz[x]%2]++;
}
// printf("%d\n",ans);
}
int main(){
n = rd(); m = rd();
rep(i,1,m) {
int x = rd(),y = rd();
E[x].push_back(y); E[y].push_back(x);
}
rep(x,1,n) if(!vis[x]) rt = x , dfs(x) , cnt[sz[x]%2]++;
// printf("***\n");
work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6420kb
input:
3 1 1 2
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements