Submission #6905631
Source Code Expand
#include<iostream> #include<map> #include<string.h> #include<queue> #include<algorithm> #include<vector> #include<string> #include<utility> #include<cstdlib> #include<math.h> #include<set> using namespace std; template<class T>inline bool chmax(T&a, T b) { if (a < b) { a = b; return 1; }return 0; } template<class T>inline bool chmin(T&a, T b) { if (a > b) { a = b; return 1; }return 0; } #define rep(n) for(int i=0;i<n;i++) typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll>pll; const int MOD = 1000000007; const int INF = 1 << 29; int par[100001],n,q; void init(int n) { rep(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() { cin >> n >> q; init(n); int p[200001], a[200001], b[200001]; for(int i=0;i<q;i++) { cin >> p[i] >> a[i] >> b[i]; } for (int i = 0; i < q; i++) { if (p[i] == 0) { unite(a[i], b[i]); } if (p[i] == 1) { if (same(a[i],b[i]))cout << "Yes" << endl; else cout << "No" << endl; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Union Find |
User | ranchan |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1263 Byte |
Status | AC |
Exec Time | 635 ms |
Memory | 3584 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 | 2 ms | 256 KB |
subtask_01_01.txt | AC | 331 ms | 2048 KB |
subtask_01_02.txt | AC | 2 ms | 640 KB |
subtask_01_03.txt | AC | 533 ms | 3328 KB |
subtask_01_04.txt | AC | 569 ms | 3584 KB |
subtask_01_05.txt | AC | 32 ms | 512 KB |
subtask_01_06.txt | AC | 34 ms | 768 KB |
subtask_01_07.txt | AC | 559 ms | 3200 KB |
subtask_01_08.txt | AC | 587 ms | 3584 KB |
subtask_01_09.txt | AC | 2 ms | 256 KB |
subtask_01_10.txt | AC | 2 ms | 640 KB |
subtask_01_11.txt | AC | 541 ms | 3200 KB |
subtask_01_12.txt | AC | 635 ms | 3584 KB |
subtask_01_13.txt | AC | 473 ms | 2560 KB |
subtask_01_14.txt | AC | 3 ms | 640 KB |
subtask_01_15.txt | AC | 557 ms | 3200 KB |
subtask_01_16.txt | AC | 569 ms | 3584 KB |
subtask_01_17.txt | AC | 393 ms | 3328 KB |
subtask_01_18.txt | AC | 393 ms | 3328 KB |