10pts神奇MLE玄关
查看原帖
10pts神奇MLE玄关
1070708
Caged_Bird楼主2024/10/30 17:01
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline void print(int n){if(n<0){putchar('-');print(-n);return;}if(n>9)print(n/10);putchar(n%10+'0');}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
int col[100005],n,m,tot;
vector<int>a[100005];
int b[100005],c[100005],ans1,ans2;
void dfs(int now,int fa,int color){
    col[now]=1;
    if(color==1)b[tot]++;
    else c[tot]++;
    for(int i:a[now]){
        if(i!=fa)dfs(i,now,(color+1)%2);
    }
}
signed main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(!col[i]){
            tot++;
            dfs(i,0,1);
        }
    }
    for(int i=1;i<=tot;i++){
        ans1+=min(b[i],c[i]);
        ans2+=max(b[i],c[i]);
    }
    cout<<ans1<<' '<<ans2;
    return 0;
}

玄关

2024/10/30 17:01
加载中...