Submission #420209
Source Code Expand
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int par[100050],ran[100050];
void init(){ for(int i=0;i<100050;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
x = find(x); y = find(y); if(x==y) return;
if(ran[x] < ran[y]) par[x] = y;
else{
par[y] = x;
if(ran[x] == ran[y]) ran[x]++;
}
}
bool same(int x,int y){ return find(x)==find(y); }
int h,w;
int main()
{
cin >> h >> w;
init();
for(int i=0;i<w;i++)
{
int q; scanf("%d",&q);
if(q==0)
{
int a,b; scanf("%d%d",&a,&b);
unite(a,b);
}
else
{
int a,b; scanf("%d%d",&a,&b);
cout << (same(a,b)?"Yes":"No") << endl;
}
}
}
Submission Info
Submission Time
2015-06-06 21:05:54+0900
Task
B - Union Find
User
IH19980412
Language
C++ (GCC 4.9.2)
Score
100
Code Size
1526 Byte
Status
AC
Exec Time
721 ms
Memory
1564 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:54:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int q; scanf("%d",&q);
^
./Main.cpp:57:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int a,b; scanf("%d%d",&a,&b);
^
./Main.cpp:62:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int a,b; scanf("%d%d",&a,&b);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
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
25 ms
1304 KB
subtask_01_01.txt
AC
340 ms
1308 KB
subtask_01_02.txt
AC
26 ms
1300 KB
subtask_01_03.txt
AC
564 ms
1308 KB
subtask_01_04.txt
AC
709 ms
1184 KB
subtask_01_05.txt
AC
59 ms
1180 KB
subtask_01_06.txt
AC
55 ms
1564 KB
subtask_01_07.txt
AC
558 ms
1180 KB
subtask_01_08.txt
AC
609 ms
1312 KB
subtask_01_09.txt
AC
27 ms
1192 KB
subtask_01_10.txt
AC
23 ms
1184 KB
subtask_01_11.txt
AC
553 ms
1304 KB
subtask_01_12.txt
AC
721 ms
1192 KB
subtask_01_13.txt
AC
570 ms
1188 KB
subtask_01_14.txt
AC
28 ms
1112 KB
subtask_01_15.txt
AC
562 ms
1188 KB
subtask_01_16.txt
AC
568 ms
1176 KB
subtask_01_17.txt
AC
412 ms
1312 KB
subtask_01_18.txt
AC
382 ms
1180 KB