This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define ub upper_bound
#define lb lower_bound
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));(s)<(e)?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(177013);
struct UFDS{
int p[300005];
UFDS(){
rep(x,0,300005) p[x]=x;
}
int par(int i){
if (i==p[i]) return i;
else return p[i]=par(p[i]);
}
void unions(int i,int j){
p[par(i)]=par(j);
}
} ufds;
int n,k,q;
int arr[1005];
int main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>k>>q;
rep(zzz,0,k){
rep(x,1,n+1) cin>>arr[x];
rep(x,1,n+1) ufds.unions(arr[x],x);
}
int a,b;
while (q--){
cin>>a>>b;
if (ufds.par(a)==ufds.par(b)) cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |