Submission #744863

#TimeUsernameProblemLanguageResultExecution timeMemory
744863sword060Kutije (COCI21_kutije)C++17
70 / 70
158 ms9400 KiB
#include <bits/stdc++.h> using namespace std; const int N=1005; int x,k,q,p[N],s[N],a[N]; int get(int a){ return (a==p[a]?a:p[a]=get(p[a])); } void merge(int l,int r){ l=get(l),r=get(r); if(l==r)return; if(s[l]>s[r])swap(l,r); s[r]+=s[l]; p[l]=r; } int main(){ ios::sync_with_stdio(0);cin.tie(0); cin>>x>>k>>q; for(int i=1;i<=x;i++)p[i]=i,s[i]=1; for(int j=1;j<=k;j++){ for(int i=1;i<=x;i++)cin>>a[i]; for(int i=1;i<=x;i++)merge(i,a[i]); } while(q--){ int l,r;cin>>l>>r; cout<<(get(l)==get(r)?"DA":"NE")<<"\n"; } 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...