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>
#define N 200005
#define ll long long int
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define fs(ar,n) fo(i,1,n) cin>>ar[i]
#define sp " "
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast2 freopen ("in.txt","r",stdin);freopen ("out.txt","w",stdout);
#define mod 1000000007
using namespace std;
ll n,m,ar[N],sum,t,dad[N],q;
int find(int x)
{
if(dad[x]==x)
return x;
return dad[x]=find(dad[x]);
}
void unite(int x,int y)
{
dad[find(x)]=find(y);
}
int main()
{
fast;
cin>>n>>m>>q;
fo(i,1,n)
dad[i]=i;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
int a;
cin>>a;
unite(j,a);
}
}
for(int i=1;i<=q;i++)
{
int a,b;
cin>>a>>b;
if(find(a)==find(b))
cout<<"DA"<<endl;
else
cout<<"NE"<<endl;
//cout<<find(a)<<sp<<find(b)<<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... |