QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#262235#7755. Game on a ForestHHY_zZhu#WA 2ms10124kbC++232.4kb2023-11-23 16:58:002023-11-23 16:58:00

Judging History

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

  • [2023-11-23 16:58:00]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10124kb
  • [2023-11-23 16:58:00]
  • 提交

answer

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define all0(x) (x).begin(),(x).end()
#define all1(x) (x).begin()+1,(x).end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define cin std::cin
#define cout std::cout
typedef long long LL;
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

const int MN = 2e5 + 20;//MaxN 记得改一下
const int INF = 2e9+1000;//INF
const LL INFLL = 8e18+1000;//INF long long 
mt19937 mrand(random_device{}());
//模板区域~~~~~~~
int f[MN],siz[MN];
int par(int x){
    if(x==f[x]) return x;
    return f[x]=par(f[x]);
}
void mer(int a,int b){
    a=par(a),b=par(b);
    if(a==b) return;
    f[a]=b;
    siz[b]+=siz[a];
}
void ini(int n){
    for(int i=1;i<=n;i++) f[i]=i,siz[i]=1;
}
//模板结束~~~~~~~
V<int> e[MN];
int vis[MN];
int z,o;
int n;
void dfs(int x,int p,int fcnt){ 
    if(p){
        int f=0;
        if(fcnt==1) f=1;
        if(siz[x]==1) f^=1;
        if(f) o++;
        else z++;
    }

    vis[x]=1;
    int now=0;
    if(fcnt==1) now=1;
    for(auto y:e[x]){
        if(siz[y]==1) now^=1;
    }
    if(now==0) z++;
    else o++;
    for(auto y:e[x]){
        if(y==p) continue;
        dfs(y,x,n-siz[y]);
    }
}
void dfs0(int x,int p){
    siz[x] = 1;
    for(auto y:e[x]){
        if(y==p) continue;
        dfs0(y,x);
        siz[x]+=siz[y];
    }
}
void solve() {
    int m;cin>>n>>m;
    ini(n);
    for(int i=1;i<=m;i++){
        int a,b;cin>>a>>b;
        mer(a,b);
        e[a].pb(b);
        e[b].pb(a);
    }
    int tot=0;
    for(int i=1;i<=n;i++){
        if(i==par(i)){
            tot^=(siz[i]==1?1:0);
        }
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs0(i,0);
            dfs(i,0,0);
        }
    }
    debug(z,o);

    if(tot==1) cout<<o<<endl;
    else cout<<z<<endl;
}
int32_t main() {
#ifndef LOCAL
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#endif
#ifdef LOCAL
   freopen("C:/Users/lijia/Desktop/vscode/in.in","r",stdin);
   freopen("C:/Users/lijia/Desktop/vscode/out.out","w",stdout);
#endif
    int tt=1;
    //cin >> tt;
    while (tt--) 
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8188kb

input:

3 1
1 2

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

4 3
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 10124kb

input:

100000 1
4647 17816

output:

99999

result:

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