#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1005;
int N, M, Q;
vector <int> G[NMAX];
int comp[NMAX];
int nr;
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> Q;
for (int i = 1; i <= M; ++ i ) {
for (int j = 1; j <= N; ++ j ) {
int x;
cin >> x;
G[j].push_back(x);
G[x].push_back(j);
}
}
}
void Dfs (int nod) {
comp[nod] = nr;
for (auto it : G[nod]) {
if (comp[it] != 0) continue;
Dfs(it);
}
}
void Precompute () {
for (int i = 1; i <= N; ++ i ) {
if (comp[i] == 0) {
++ nr;
Dfs(i);
}
}
}
void Solve () {
for (int i = 1; i <= Q; ++ i ) {
int x, y;
cin >> x >> y;
cout << (comp[x] == comp[y] ? "DA\n" : "NE\n");
}
}
int main () {
Read();
Precompute();
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
5656 KB |
Output is correct |
2 |
Correct |
61 ms |
4908 KB |
Output is correct |
3 |
Correct |
61 ms |
4700 KB |
Output is correct |
4 |
Correct |
83 ms |
5640 KB |
Output is correct |
5 |
Correct |
70 ms |
5572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
420 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
488 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
5656 KB |
Output is correct |
2 |
Correct |
61 ms |
4908 KB |
Output is correct |
3 |
Correct |
61 ms |
4700 KB |
Output is correct |
4 |
Correct |
83 ms |
5640 KB |
Output is correct |
5 |
Correct |
70 ms |
5572 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
484 KB |
Output is correct |
8 |
Correct |
1 ms |
420 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
488 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
157 ms |
18384 KB |
Output is correct |
27 |
Correct |
151 ms |
18196 KB |
Output is correct |
28 |
Correct |
141 ms |
15908 KB |
Output is correct |
29 |
Correct |
141 ms |
17868 KB |
Output is correct |
30 |
Correct |
133 ms |
15564 KB |
Output is correct |
31 |
Correct |
139 ms |
15952 KB |
Output is correct |
32 |
Correct |
147 ms |
17620 KB |
Output is correct |
33 |
Correct |
151 ms |
17472 KB |
Output is correct |
34 |
Correct |
153 ms |
17560 KB |
Output is correct |
35 |
Correct |
170 ms |
17956 KB |
Output is correct |