Submission #1102459

#TimeUsernameProblemLanguageResultExecution timeMemory
1102459yavuzskarahanKutije (COCI21_kutije)C++17
70 / 70
117 ms1928 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 5; int n, m, q, a, b, arr[N]; struct DSU{ int par[N], stsize[N]; DSU(){ for(int i = 1; i < N; i++) par[i] = i, stsize[i] = 1; } int setfind(int a){ if(par[a] == a) return a; else return par[a] = setfind(par[a]); } void setunion(int a, int b){ a = setfind(a), b = setfind(b); if(a != b){ if(stsize[b] > stsize[a]) swap(a, b); par[b] = par[a]; stsize[a] += stsize[b]; } } }; DSU dsu; int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n >> m >> q; for(int i = 1; i <= m; i++){ for(int i = 1; i <= n; i++) cin >> arr[i]; for(int i = 1; i <= n; i++) dsu.setunion(i, arr[i]); } while(q--){ cin >> a >> b; if(dsu.setfind(a) == dsu.setfind(b)) 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...