Submission #420591
Source Code Expand
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1};
const int MAX_N = 100000;
int par[MAX_N];
void init(int n){
REP(i, n) par[i] = i;
}
int root(int x){
if(par[x] == x){
return x;
}else{
return par[x] = root(par[x]);
}
}
bool same(int x, int y){
return root(x) == root(y);
}
void unite(int x, int y){
x = root(x);
y = root(y);
if(x == y) return ;
par[x] = y;
}
int main() {
int n, q;
cin >> n >> q;
init(n);
REP(i, q){
int p, a, b;
cin >> p >> a >> b;
if(p){//判定
cout << (same(a, b) ? "Yes" : "No") << endl;
}else{//連結
unite(a, b);
}
}
}
Submission Info
Submission Time |
|
Task |
B - Union Find |
User |
turanegaku |
Language |
C++11 (GCC 4.9.2) |
Score |
100 |
Code Size |
1705 Byte |
Status |
AC |
Exec Time |
966 ms |
Memory |
1312 KB |
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 |
26 ms |
668 KB |
subtask_01_01.txt |
AC |
512 ms |
920 KB |
subtask_01_02.txt |
AC |
26 ms |
1188 KB |
subtask_01_03.txt |
AC |
719 ms |
736 KB |
subtask_01_04.txt |
AC |
966 ms |
1184 KB |
subtask_01_05.txt |
AC |
66 ms |
804 KB |
subtask_01_06.txt |
AC |
72 ms |
1308 KB |
subtask_01_07.txt |
AC |
797 ms |
928 KB |
subtask_01_08.txt |
AC |
802 ms |
1120 KB |
subtask_01_09.txt |
AC |
27 ms |
796 KB |
subtask_01_10.txt |
AC |
27 ms |
1184 KB |
subtask_01_11.txt |
AC |
734 ms |
800 KB |
subtask_01_12.txt |
AC |
866 ms |
1312 KB |
subtask_01_13.txt |
AC |
625 ms |
928 KB |
subtask_01_14.txt |
AC |
29 ms |
1188 KB |
subtask_01_15.txt |
AC |
829 ms |
700 KB |
subtask_01_16.txt |
AC |
904 ms |
1308 KB |
subtask_01_17.txt |
AC |
642 ms |
1304 KB |
subtask_01_18.txt |
AC |
625 ms |
1188 KB |