Submission #862551

#TimeUsernameProblemLanguageResultExecution timeMemory
862551Cyber_WolfKutije (COCI21_kutije)C++17
70 / 70
911 ms11900 KiB
#include <bits/stdc++.h> using namespace std; #define lg long long const lg N = 2e5+5; lg par[N], compSize[N]; lg get(lg src) { if(par[src] == src) return src; return par[src] = get(par[src]); } void join(lg u, lg v) { u = get(u); v = get(v); if(u == v) return; if(compSize[u] > compSize[v]) swap(u, v); par[u] = v; compSize[v] += compSize[u]; return; } int main() { lg n, m, q; cin >> n >> m >> q; for(int i = 1; i <= n; i++) par[i] = i, compSize[i] = 1; for(int i = 0; i < m; i++) { for(int j = 1; j <= n; j++) { lg x; cin >> x; join(x, j); } } while(q--) { lg a, b; cin >> a >> b; cout << (get(a) == get(b) ? "DA" : "NE") << '\n'; } } /* -2 -1 -2 -1 1 -2 -2 -2 -1 -2 -1 -2 -1 -1 -1 -1 -2 -1 -2 -1 -2 -2 -2 -2 -2 -2 -2 -2 0 -2 -2 -2 -2 -2 -2 -2 -1 -2 -1 -2 0 -2 -2 -2 -1 -2 -1 -2 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...