Submission #3009668
Source Code Expand
#include <bits/stdc++.h> using namespace std; class DisjointSet { public: vector<int> rank, p; DisjointSet() {} DisjointSet(int size) { rank.resize(size, 0); p.resize(size, 0); for (int i = 0; i < size; i++) makeSet(i); } void makeSet(int x) { p[x] = x; rank[x] = 0; } bool same(int x, int y) { return findSet(x) == findSet(y); } void unite(int x, int y) { link(findSet(x), findSet(y)); } void link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; } else { p[x] = y; if (rank[x] == rank[y]) rank[y]++; } } int findSet(int x) { if (x != p[x]) { p[x] = findSet(p[x]); } return p[x]; } }; int main() { int n, a, b, q; int t; cin >> n >> q; DisjointSet ds = DisjointSet(n); for (int i = 0; i < q; i++) { cin >> t >> a >> b; if (t == 0) ds.unite(a, b); else if (t == 1) { if (ds.same(a, b)) cout << 1 << endl; else cout << 0 << endl; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Equals |
User | atumari |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1220 Byte |
Status | WA |
Exec Time | 84 ms |
Memory | 1024 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | WA | 1 ms | 256 KB |
0_001.txt | WA | 1 ms | 256 KB |
0_002.txt | WA | 1 ms | 256 KB |
0_003.txt | WA | 1 ms | 256 KB |
1_004.txt | WA | 44 ms | 256 KB |
1_005.txt | WA | 84 ms | 1024 KB |
1_006.txt | WA | 84 ms | 1024 KB |
1_007.txt | WA | 1 ms | 256 KB |
1_008.txt | WA | 1 ms | 256 KB |
1_009.txt | WA | 1 ms | 256 KB |
1_010.txt | WA | 1 ms | 256 KB |
1_011.txt | WA | 1 ms | 256 KB |
1_012.txt | WA | 1 ms | 256 KB |
1_013.txt | WA | 1 ms | 256 KB |
1_014.txt | WA | 3 ms | 256 KB |
1_015.txt | WA | 1 ms | 256 KB |
1_016.txt | WA | 1 ms | 256 KB |
1_017.txt | WA | 2 ms | 256 KB |
1_018.txt | WA | 41 ms | 256 KB |
1_019.txt | WA | 2 ms | 1024 KB |
1_020.txt | WA | 2 ms | 1024 KB |
1_021.txt | WA | 2 ms | 1024 KB |
1_022.txt | WA | 84 ms | 1024 KB |