Submission #7506245


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int father[100005];
inline int find(int x)//查找根
{
    if(father[x]!=x)
      father[x]=find(father[x]);//路径压缩
    return father[x];
}
inline void merge(int x,int y)//合并
{
    x=find(x);
    y=find(y);
    father[y]=x;
} 
inline bool judge(int x,int y)//判断
{
    if(find(x)==find(y))
      return true;
    else
      return false;
}
inline void init(int n)//初始化
{
    for(int i=1;i<=n;i++)
      father[i]=i;
}
int main()
{
    int n,m,z,a,b;
    scanf("%d%d",&n,&m);
    init(n);
    for(int i=1;i<=m;i++)
      {
        scanf("%d%d%d",&z,&a,&b);
        if(!z)
          merge(a,b);
        else
          if(judge(a,b))
            printf("Yes\n");
          else
            printf("No\n");
      }
    return 0;
}


Submission Info

Submission Time
Task B - Union Find
User luogu_bot4
Language C++ (GCC 5.4.1)
Score 100
Code Size 842 Byte
Status AC
Exec Time 53 ms
Memory 1280 KB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt
All 00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 256 KB
subtask_01_01.txt AC 29 ms 640 KB
subtask_01_02.txt AC 1 ms 640 KB
subtask_01_03.txt AC 41 ms 1024 KB
subtask_01_04.txt AC 49 ms 1280 KB
subtask_01_05.txt AC 4 ms 256 KB
subtask_01_06.txt AC 5 ms 640 KB
subtask_01_07.txt AC 45 ms 768 KB
subtask_01_08.txt AC 49 ms 1152 KB
subtask_01_09.txt AC 1 ms 256 KB
subtask_01_10.txt AC 1 ms 640 KB
subtask_01_11.txt AC 42 ms 896 KB
subtask_01_12.txt AC 49 ms 1152 KB
subtask_01_13.txt AC 37 ms 768 KB
subtask_01_14.txt AC 1 ms 640 KB
subtask_01_15.txt AC 43 ms 896 KB
subtask_01_16.txt AC 49 ms 1152 KB
subtask_01_17.txt AC 48 ms 896 KB
subtask_01_18.txt AC 53 ms 896 KB