Submission #1069593


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int bcj1[200010],bcj2[200010];
int father1(int k)
{
    return bcj1[k]==k?k:bcj1[k]=father1(bcj1[k]);
}
void join1(int x,int y)
{
    int fa,fb;
    fa=father1(x);fb=father1(y);
    bcj1[fb]=fa;
}
int father2(int k)
{
    return bcj2[k]==k?k:bcj2[k]=father2(bcj2[k]);
}
void join2(int x,int y)
{
    int fa,fb;
    fa=father2(x);fb=father2(y);
    bcj2[fb]=fa;
}
struct haha
{
    int p,q,no,ans;
}pp[200010];
bool cmp1(haha a,haha b)
{
    if (a.p==b.p) return a.q<b.q;
    return a.p<b.p;
}
bool cmp2(haha a,haha b)
{
    return a.no<b.no;
}
int main()
{
    int n,k,l,a,b,i,j,m,cnt;
    cin>>n>>k>>l;
    for(i=1;i<=n;i++)
    {
        bcj1[i]=bcj2[i]=i;
        pp[i].ans=0;pp[i].no=i;
    }
    for(i=1;i<=k;i++)
    {
        scanf("%d%d",&a,&b);
        join1(a,b);
    }
    for(i=1;i<=l;i++)
    {
        scanf("%d%d",&a,&b);
        join2(a,b);
    }
    for(i=1;i<=n;i++)
    {
        bcj1[i]=father1(bcj1[i]);
        pp[i].p=bcj1[i];
        bcj2[i]=father2(bcj2[i]);
        pp[i].q=bcj2[i];
    }
    sort(pp+1,pp+1+n,cmp1);cnt=0;
    pp[0].p=pp[0].q=0;j=1;
    for(i=1;i<=n+1;i++)
    {
        if (i<=n && pp[i].p==pp[i-1].p && pp[i].q==pp[i-1].q) continue;
        for(m=j;m<=i-1;m++)
            pp[m].ans=i-j;
        j=i;
    }
    sort(pp+1,pp+1+n,cmp2);
    for(i=1;i<=n;i++)
        printf("%d ",pp[i].ans);
    cout<<endl;
    return 0;
}

Submission Info

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

Compile Error

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

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 3 ms 256 KB
subtask0_2.txt AC 3 ms 256 KB
subtask1_0.txt AC 31 ms 256 KB
subtask1_1.txt AC 77 ms 5120 KB
subtask1_10.txt AC 33 ms 384 KB
subtask1_11.txt AC 72 ms 4608 KB
subtask1_12.txt AC 84 ms 4864 KB
subtask1_13.txt AC 90 ms 5248 KB
subtask1_14.txt AC 80 ms 4224 KB
subtask1_2.txt AC 71 ms 3968 KB
subtask1_3.txt AC 93 ms 5248 KB
subtask1_4.txt AC 83 ms 4352 KB
subtask1_5.txt AC 33 ms 384 KB
subtask1_6.txt AC 68 ms 4352 KB
subtask1_7.txt AC 90 ms 5248 KB
subtask1_8.txt AC 95 ms 5376 KB
subtask1_9.txt AC 74 ms 3584 KB