Submission #1069288


Source Code Expand

#include<cstdio>
#include<queue>
#include<climits>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<ctype.h>
#include<set>
#include<vector>
#include<map>
#include<time.h>
#include<list>
#include<stack>
#include<iostream>
using namespace std;
#define mod 1000000007
#define mem(x,k ) memset(x, (k) ,sizeof(x))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define sca scanf
#define pri printf
#define fi first
#define se second

typedef long long LL;
typedef long double LD;
typedef pair< int , int  > pii;

const LL INFLL=0x3f3f3f3f3f3f3f3fll;
const int INF=0x7fffffff;
const double PI=acos(-1.0);
const double  eps=1e-9;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
int n,m,k;
int f[200005];
int f2[200005];
map<pair<int ,int >,int> G;
int Father(int k)
{
    if (k==f[k]) return k;
	return f[k]=Father(f[k]);
}

void Union(int x,int y)
{
    if (Father(x)==Father(y)) return;
    else
    {
        f[ f[x] ]=f[y];
        return;
    }
}
int Father2(int k)
{
    if (k==f2[k]) return k;
	return f2[k]=Father2(f2[k]);
}

void Union2(int x,int y)
{
    if (Father2(x)==Father2(y)) return;
    else
    {
        f2[ f2[x] ]=f2[y];
        return;
    }
}
int main(){
    scanf("%d%d%d",&n,&k,&m);
    for (int i=1;i<=n;i++){
        f[i]=f2[i]=i;
    }
    for (int i=1;i<=k;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        Union2(u,v);
    }
    for (int i=1;i<=m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        Union(u,v);
    }
    for (int i=1;i<=n;i++){
        G[make_pair(Father(i),Father2(i))]++;
    }
    for (int i=1;i<=n;i++){
        //printf("@%d@",Father(i));
        printf("%d",G[make_pair(Father(i),Father2(i))]);
        if (i!=n) printf(" ");
    }
    printf("\n");
    return 0;
}



Submission Info

Submission Time
Task D - Connectivity
User vjudge1
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1802 Byte
Status AC
Exec Time 133 ms
Memory 13568 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:72:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&k,&m);
                             ^
./Main.cpp:78:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
                            ^
./Main.cpp:83:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 18
Set Name Test Cases
Sample subtask0_0.txt, subtask0_1.txt, subtask0_2.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt
Case Name Status Exec Time Memory
subtask0_0.txt AC 3 ms 256 KB
subtask0_1.txt AC 2 ms 256 KB
subtask0_2.txt AC 3 ms 256 KB
subtask1_0.txt AC 31 ms 256 KB
subtask1_1.txt AC 133 ms 13568 KB
subtask1_10.txt AC 33 ms 256 KB
subtask1_11.txt AC 120 ms 12032 KB
subtask1_12.txt AC 104 ms 11520 KB
subtask1_13.txt AC 105 ms 12672 KB
subtask1_14.txt AC 96 ms 8832 KB
subtask1_2.txt AC 89 ms 8704 KB
subtask1_3.txt AC 107 ms 12544 KB
subtask1_4.txt AC 100 ms 9728 KB
subtask1_5.txt AC 33 ms 256 KB
subtask1_6.txt AC 112 ms 11392 KB
subtask1_7.txt AC 110 ms 12672 KB
subtask1_8.txt AC 111 ms 12672 KB
subtask1_9.txt AC 83 ms 6400 KB