Submission #19676618


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++ (GCC 9.2.1)
Score 400
Code Size 865 Byte
Status AC
Exec Time 136 ms
Memory 27552 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
./Main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 27
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt
Case Name Status Exec Time Memory
0_000.txt AC 14 ms 12884 KB
0_001.txt AC 17 ms 13056 KB
0_002.txt AC 17 ms 13060 KB
1_003.txt AC 14 ms 12932 KB
1_004.txt AC 13 ms 13024 KB
1_005.txt AC 48 ms 16752 KB
1_006.txt AC 14 ms 12980 KB
1_007.txt AC 14 ms 13164 KB
1_008.txt AC 51 ms 16808 KB
1_009.txt AC 132 ms 22948 KB
1_010.txt AC 136 ms 22896 KB
1_011.txt AC 134 ms 22744 KB
1_012.txt AC 74 ms 27552 KB
1_013.txt AC 69 ms 21256 KB
1_014.txt AC 53 ms 15896 KB
1_015.txt AC 61 ms 21628 KB
1_016.txt AC 11 ms 12924 KB
1_017.txt AC 31 ms 14108 KB
1_018.txt AC 43 ms 15664 KB
1_019.txt AC 116 ms 21096 KB
1_020.txt AC 110 ms 21172 KB
1_021.txt AC 13 ms 12984 KB
1_022.txt AC 11 ms 13008 KB
1_023.txt AC 91 ms 19400 KB
1_024.txt AC 58 ms 16896 KB
1_025.txt AC 122 ms 21120 KB
1_026.txt AC 66 ms 18116 KB