Submission #851818

#TimeUsernameProblemLanguageResultExecution timeMemory
851818vjudge1Kutije (COCI21_kutije)C++17
70 / 70
136 ms1984 KiB
//author: #include <bits/stdc++.h> using namespace std; using i64 = long long; #define ONLINE_JUDGE struct DSU { vector <int> par; DSU(int n) { par.resize(n); iota(par.begin(), par.end(), 0ll); } bool same(int a, int b) { return get(a) == get(b); } inline int get(int a) { return par[a] = (par[a] == a ? a : get(par[a])); } void unite(int u, int v) { par[get(u)] = get(v); } }; void solve() { int n, m, q; cin >> n >> m >> q; DSU dsu(n +1); for(int i = 1; i <= m; i++) { for(int j = 1; j <= n; j++) { int x; cin >> x; dsu.unite(j, x); } } for(int i = 1; i <= q; i++) { int a, b; cin >> a >> b; cout << (dsu.same(a, b) ? "DA" : "NE") << "\n"; } return; } signed main() { #ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...