# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
515818 | aris12345678 | Kutije (COCI21_kutije) | C++14 | 210 ms | 9392 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005;
int par[mxN], sz[mxN];
void make_set(int x) {
par[x] = x, sz[x] = 1;
}
int find_set(int x) {
return par[x] == x ? x : par[x] = find_set(par[x]);
}
void union_sets(int x, int y) {
x = find_set(x), y = find_set(y);
if(x == y) return;
if(sz[x] < sz[y])
swap(x, y);
par[y] = x, sz[x] += sz[y];
}
int main() {
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
for(int i = 0; i < n; i++)
make_set(i);
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
int x;
scanf("%d", &x);
union_sets(j, x-1);
}
}
while(q--) {
int x, y;
scanf("%d %d", &x, &y);
if(find_set(x-1) == find_set(y-1))
printf("DA\n");
else
printf("NE\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |