Submission #534730

#TimeUsernameProblemLanguageResultExecution timeMemory
534730kappaKutije (COCI21_kutije)C++14
35 / 70
1075 ms9408 KiB
#include <bits/stdc++.h> using namespace std; long long n, m, q; struct node{ long long parent; long long rank; }; node v[200005]; long long find(long long u){ if(u != v[u].parent){ v[u].parent = find(v[u].parent); } return v[u].parent; } void merge(long long x, long long y){ long long px = find(x); long long py = find(y); if(v[px].rank > v[py].rank){ v[py].parent = px; }else{ v[px].parent = py; } if(v[px].rank == v[py].rank){ v[py].rank++; } } int main(){ cin >> n >> m >> q; for (int i = 1; i <= n; ++i) { v[i].parent = i; v[i].rank = 0; } for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { int t; cin >> t; merge(t, j); } } while(q--){ int l, r; cin >> l >> r; if(find(l) == find(r)){ cout << "DA\n"; } else{ cout << "NE\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...