#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
const int N = 1e6,mod = 1e9+7;
int dsu[N],s[N];
int root(int x)
{
while(dsu[x]!=x)
{
dsu[x] = dsu[dsu[x]];
x = dsu[x];
}
return x;
}
void onion(int x,int y)
{
x = root(x);
y = root(y);
if(s[x]<s[y])
swap(x,y);
dsu[y] = x;
s[x]+=s[y];
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
for(int i = 1;i<=n;i++)
{
dsu[i] = i;
s[i] = 1;
}
for(int l = 0;l<m;l++)
{
for(int i = 1;i<=n;i++)
{
int a;
cin>>a;
onion(i,a);
}
}
while(q--)
{
int a,b;
cin>>a>>b;
a = root(a);
b = root(b);
if(a==b)
cout<<"DA"<<endl;
else cout<<"NE"<<endl;
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
5568 KB |
Output is correct |
2 |
Correct |
76 ms |
4824 KB |
Output is correct |
3 |
Correct |
71 ms |
4632 KB |
Output is correct |
4 |
Correct |
86 ms |
5520 KB |
Output is correct |
5 |
Correct |
89 ms |
5584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
5568 KB |
Output is correct |
2 |
Correct |
76 ms |
4824 KB |
Output is correct |
3 |
Correct |
71 ms |
4632 KB |
Output is correct |
4 |
Correct |
86 ms |
5520 KB |
Output is correct |
5 |
Correct |
89 ms |
5584 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
328 KB |
Output is correct |
16 |
Correct |
2 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
248 KB |
Output is correct |
26 |
Correct |
222 ms |
9388 KB |
Output is correct |
27 |
Correct |
153 ms |
9416 KB |
Output is correct |
28 |
Correct |
128 ms |
7752 KB |
Output is correct |
29 |
Correct |
164 ms |
9196 KB |
Output is correct |
30 |
Correct |
145 ms |
8068 KB |
Output is correct |
31 |
Correct |
147 ms |
8016 KB |
Output is correct |
32 |
Correct |
168 ms |
9356 KB |
Output is correct |
33 |
Correct |
172 ms |
9452 KB |
Output is correct |
34 |
Correct |
163 ms |
9528 KB |
Output is correct |
35 |
Correct |
169 ms |
9392 KB |
Output is correct |