Submission #19676604


Source Code Expand

Copy
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=4e5+5;
const int M=2e5+5;
vector<int>g[N];
bool vis[N];
int d[M<<1];
int res,f;
void dfs(int u,int p)
{
    if(!vis[u])
    {
        res++;
        vis[u]=1;
    }
    for(auto v:g[u])
    {
        if(v==p) continue;
        if(vis[v]) f=1;
        else dfs(v,u);
    }
}
int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        d[++cnt]=a;
        d[++cnt]=b;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans=0;
    for(int i=1;i<=cnt;i++)
    {
        if(!vis[d[i]])
        {
            res=0,f=0;
            dfs(d[i],0);
            if(f==0) ans+=(res-1);
            else ans+=res;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Submission Info

Submission Time
Task B - Reversible Cards
User whix
Language C++ (Clang 10.0.0)
Score 0
Code Size 865 Byte
Status CE

Compile Error

./Main.cpp:1:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>
         ^~~~~~~~~~~~~~~
1 error generated.