# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872759 | rainboy | Experimental Charges (NOI19_charges) | C11 | 25 ms | 2588 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 <stdio.h>
#include <string.h>
#define N 100000
int ds[N * 2];
int find(int i) {
return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}
void join(int i, int j) {
i = find(i);
j = find(j);
if (i == j)
return;
if (ds[i] > ds[j])
ds[i] = j;
else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i;
}
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
memset(ds, -1, n * 2 * sizeof *ds);
while (q--) {
static char s[2];
int i, j;
scanf("%s%d%d", s, &i, &j), i--, j--;
if (s[0] == 'A')
join(i << 1 | 0, j << 1 | 1), join(i << 1 | 1, j << 1 | 0);
else if (s[0] == 'R')
join(i << 1 | 0, j << 1 | 0), join(i << 1 | 1, j << 1 | 1);
else
if (find(i << 1 | 0) == find(j << 1 | 1))
printf("A\n");
else if (find(i << 1 | 0) == find(j << 1 | 0))
printf("R\n");
else
printf("?\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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |