#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,O3,unroll-loops")
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>
#define vvpi vector<vpi>
#define vb vector<bool>
#define vvb vector<vb>
#define endl "\n"
#define sp << " " <<
#define F(i, s, n) for(int i = s; i < n; i++)
#define pb push_back
#define fi first
#define se second
int inf = LLONG_MAX >> 3;
vi dad(1001);
int find(int a) {
if(dad[a] == a) return a;
return dad[a] = find(dad[a]);
}
void unite(int a, int b) {
dad[find(a)] = find(b);
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
F(i, 0, n) dad[i] = i;
F(i, 0, m) {
F(j, 0, n) {
int x;
cin >> x;
x--;
unite(x, j);
}
}
F(i, 0, q) {
int x, y;
cin >> x >> y;
x--, y--;
if(find(x) == find(y)) cout << "DA" << endl;
else cout << "NE" << endl;
}
}
void setIO() {
ios::sync_with_stdio(0); cin.tie(0);
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
signed main() {
setIO();
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
4020 KB |
Output is correct |
2 |
Correct |
65 ms |
3548 KB |
Output is correct |
3 |
Correct |
61 ms |
3408 KB |
Output is correct |
4 |
Correct |
73 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
4020 KB |
Output is correct |
2 |
Correct |
65 ms |
3548 KB |
Output is correct |
3 |
Correct |
61 ms |
3408 KB |
Output is correct |
4 |
Correct |
73 ms |
3864 KB |
Output is correct |
5 |
Correct |
78 ms |
3932 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
124 ms |
5984 KB |
Output is correct |
27 |
Correct |
126 ms |
5936 KB |
Output is correct |
28 |
Correct |
115 ms |
5048 KB |
Output is correct |
29 |
Correct |
119 ms |
5660 KB |
Output is correct |
30 |
Correct |
112 ms |
5164 KB |
Output is correct |
31 |
Correct |
102 ms |
5020 KB |
Output is correct |
32 |
Correct |
123 ms |
5972 KB |
Output is correct |
33 |
Correct |
128 ms |
5800 KB |
Output is correct |
34 |
Correct |
120 ms |
5908 KB |
Output is correct |
35 |
Correct |
128 ms |
6004 KB |
Output is correct |