#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
vector<int> adg[n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
int a;
cin >> a;
a--;
adg[a].push_back(j);
}
}
bool reach[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
reach[i][j]=0;
}
}
for(int i=0; i<n; i++){
queue<int> que;
que.push(i);
reach[i][i]=true;
while(!que.empty()){
int cur = que.front();
que.pop();
for(auto u : adg[cur]){
if(!reach[i][u]){
reach[i][u]=true;
que.push(u);
}
}
}
}
// for(int i=0; i<n; i++){
// cout << i << ": ";
// for(auto u : adg[i]){
// cout << u;
// }
// cout << '\n';
// }
for(int query=0; query<q; query++){
int a, b;
cin >> a >> b;
a--;
b--;
if(reach[a][b]){
cout << "DA\n";
}
else{
cout << "NE\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
6576 KB |
Output is correct |
2 |
Correct |
64 ms |
5872 KB |
Output is correct |
3 |
Correct |
54 ms |
5404 KB |
Output is correct |
4 |
Correct |
90 ms |
6612 KB |
Output is correct |
5 |
Correct |
74 ms |
6572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
368 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
6576 KB |
Output is correct |
2 |
Correct |
64 ms |
5872 KB |
Output is correct |
3 |
Correct |
54 ms |
5404 KB |
Output is correct |
4 |
Correct |
90 ms |
6612 KB |
Output is correct |
5 |
Correct |
74 ms |
6572 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
368 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
201 ms |
14988 KB |
Output is correct |
27 |
Correct |
119 ms |
14884 KB |
Output is correct |
28 |
Correct |
708 ms |
12596 KB |
Output is correct |
29 |
Correct |
497 ms |
14392 KB |
Output is correct |
30 |
Correct |
95 ms |
12644 KB |
Output is correct |
31 |
Correct |
109 ms |
12740 KB |
Output is correct |
32 |
Correct |
934 ms |
14464 KB |
Output is correct |
33 |
Correct |
116 ms |
14468 KB |
Output is correct |
34 |
Correct |
196 ms |
14500 KB |
Output is correct |
35 |
Correct |
151 ms |
14744 KB |
Output is correct |