Submission #851815

# Submission time Handle Problem Language Result Execution time Memory
851815 2023-09-20T16:20:36 Z vjudge1 Kutije (COCI21_kutije) C++17
70 / 70
128 ms 9556 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 1e3+1;
vi dad(N);

int find(int x) {
	if (x == dad[x]) return x;
	return dad[x] = find(dad[x]);
}
void unite(int x,int y) {
	dad[find(x)] = find(y);
}

void solve() {
	int n,m,q;
	cin >> n >> m >> q;
	for (int i=1;i<=n;i++) dad[i] = i;
	for (int i=1;i<=m;i++) {
		vi a(n+1);
		for (int j=1;j<=n;j++) cin >> a[j];
		for (int j=1;j<=n;j++) {
			if(j!=a[j]){
				unite(j,a[j]);
			}
		}
	}
	while (q--) {
		int a,b;
		cin >> a >> b;
		cout << ((find(a) == find(b))?"DA\n":"NE\n");
	}
}    

 
 
 
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
 
 
 
# Verdict Execution time Memory Grader output
1 Correct 63 ms 5564 KB Output is correct
2 Correct 55 ms 4944 KB Output is correct
3 Correct 52 ms 4576 KB Output is correct
4 Correct 65 ms 5704 KB Output is correct
5 Correct 68 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 496 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 496 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 496 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 5564 KB Output is correct
2 Correct 55 ms 4944 KB Output is correct
3 Correct 52 ms 4576 KB Output is correct
4 Correct 65 ms 5704 KB Output is correct
5 Correct 68 ms 5592 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 496 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 476 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 480 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 496 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 111 ms 9544 KB Output is correct
27 Correct 114 ms 9416 KB Output is correct
28 Correct 105 ms 7864 KB Output is correct
29 Correct 108 ms 9044 KB Output is correct
30 Correct 100 ms 8020 KB Output is correct
31 Correct 96 ms 8116 KB Output is correct
32 Correct 113 ms 9392 KB Output is correct
33 Correct 117 ms 9552 KB Output is correct
34 Correct 109 ms 9556 KB Output is correct
35 Correct 128 ms 9552 KB Output is correct