Submission #862585

#TimeUsernameProblemLanguageResultExecution timeMemory
862585Mizo_CompilerKutije (COCI21_kutije)C++14
70 / 70
119 ms5972 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double ld; #define pb push_back #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define F first #define S second const int N = 1005; int p[N], sz[N]; int findp(int u) { return p[u] = (p[u] == u ? u : findp(p[u])); } void merge(int u, int v) { u = findp(u), v = findp(v); if (u == v)return; if (sz[u] < sz[v])swap(u, v); sz[u] += sz[v]; p[v] = u; } int main () { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, q; cin >> n >> m >> q; for (int i = 1; i <= n; i++) { p[i] = i; sz[i] = 1; } while (m--) { for (int i = 1; i <= n; i++) { int x; cin >> x; merge(i, x); } } while (q--) { int a, b; cin >> a >> b; cout << (findp(a) == findp(b) ? "DA\n" : "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...