Submission #866672

#TimeUsernameProblemLanguageResultExecution timeMemory
866672epicci23Kutije (COCI21_kutije)C++17
70 / 70
142 ms9648 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back #define endl "\n" #define int long long #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() constexpr int N = 1005; int par[N]; int siz[N]; int find(int a){ if(par[a]==a) return a; return par[a]=find(par[a]); } void unite(int a,int b){ a=find(a),b=find(b); if(a==b) return; if(siz[a]>siz[b]) swap(a,b); siz[b]+=siz[a]; par[a]=b; } void solve(){ iota(par,par+N,0LL); fill(siz,siz+N,1LL); int n,m,q; cin >> n >> m >> q; for(int j=1;j<=m;j++){ for(int i=1;i<=n;i++){ int u; cin >> u; unite(i,u); } } while(q--){ int a,b; cin >> a >> b; if(find(a)==find(b)) cout << "DA\n"; else cout << "NE\n"; } } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); 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...