#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=2e5+5;
int const mod=1e9+7;
vector<int> adj[N];
int com[N],c=0;
void dfs(int node){
com[node]=c;
for(int i:adj[node])
if(com[i]==0)
dfs(i);
}
int main(){
int n,m,q;
cin>>n>>m>>q;
while(m--){
for(int i=1;i<=n;i++){
int p;
cin>>p;
adj[p].push_back(i);
adj[i].push_back(p);
}
}
for (int i = 1; i <=n; ++i)
if(com[i]==0){
c++;
dfs(i);
}
while(q--){
int u,v;
cin>>u>>v;
if(com[u]==com[v])
cout<<"DA"<<endl;
else
cout<<"NE"<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
640 ms |
7172 KB |
Output is correct |
2 |
Correct |
553 ms |
6976 KB |
Output is correct |
3 |
Correct |
512 ms |
6736 KB |
Output is correct |
4 |
Correct |
691 ms |
7248 KB |
Output is correct |
5 |
Correct |
666 ms |
7248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
3 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
4 ms |
5724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5724 KB |
Output is correct |
2 |
Correct |
3 ms |
5724 KB |
Output is correct |
3 |
Correct |
2 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
4 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5724 KB |
Output is correct |
16 |
Correct |
2 ms |
5796 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5720 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
640 ms |
7172 KB |
Output is correct |
2 |
Correct |
553 ms |
6976 KB |
Output is correct |
3 |
Correct |
512 ms |
6736 KB |
Output is correct |
4 |
Correct |
691 ms |
7248 KB |
Output is correct |
5 |
Correct |
666 ms |
7248 KB |
Output is correct |
6 |
Correct |
2 ms |
5724 KB |
Output is correct |
7 |
Correct |
3 ms |
5724 KB |
Output is correct |
8 |
Correct |
2 ms |
5724 KB |
Output is correct |
9 |
Correct |
2 ms |
5724 KB |
Output is correct |
10 |
Correct |
2 ms |
5724 KB |
Output is correct |
11 |
Correct |
2 ms |
5724 KB |
Output is correct |
12 |
Correct |
2 ms |
5724 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
4 ms |
5724 KB |
Output is correct |
16 |
Correct |
2 ms |
5724 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
2 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5796 KB |
Output is correct |
22 |
Correct |
2 ms |
5724 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
3 ms |
5724 KB |
Output is correct |
25 |
Correct |
2 ms |
5724 KB |
Output is correct |
26 |
Correct |
808 ms |
15920 KB |
Output is correct |
27 |
Correct |
756 ms |
15996 KB |
Output is correct |
28 |
Correct |
636 ms |
14928 KB |
Output is correct |
29 |
Correct |
801 ms |
15628 KB |
Output is correct |
30 |
Correct |
624 ms |
14496 KB |
Output is correct |
31 |
Correct |
632 ms |
14932 KB |
Output is correct |
32 |
Correct |
779 ms |
15448 KB |
Output is correct |
33 |
Correct |
742 ms |
15184 KB |
Output is correct |
34 |
Correct |
775 ms |
15176 KB |
Output is correct |
35 |
Correct |
756 ms |
15596 KB |
Output is correct |