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 <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 50000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
char ss[N * 2][16]; int aa[N * 2];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = strcmp(ss[ii[j]], ss[i_]);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int ds[N * 2], aa[N * 2];
int find(int i) {
return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}
int join(int i, int j) {
i = find(i);
j = find(j);
if (i == j)
return 1;
if (aa[i] != -1 && aa[j] != -1 && aa[i] != aa[j])
return 0;
if (ds[i] > ds[j]) {
ds[i] = j;
if (aa[j] == -1)
aa[j] = aa[i];
} else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i;
if (aa[i] == -1)
aa[i] = aa[j];
}
return 1;
}
int main() {
static int ii[N * 2];
int n, i;
scanf("%d", &n);
for (i = 0; i < n * 2; i++)
scanf("%s", ss[i]);
for (i = 0; i < n * 2; i++)
aa[i] = isdigit(ss[i][0]) ? atoi(ss[i]) : -1;
memset(ds, -1, n * 2 * sizeof *ds);
for (i = 0; i < n; i++)
if (!join(i, n + i)) {
printf("NE\n");
return 0;
}
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
for (i = 0; i < n * 2; i++)
if (i > 0 && strcmp(ss[ii[i]], ss[ii[i - 1]]) == 0 && !join(ii[i], ii[i - 1])) {
printf("NE\n");
return 0;
}
printf("DA\n");
return 0;
}
Compilation message (stderr)
zamjena.c: In function 'main':
zamjena.c:69:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
zamjena.c:71:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%s", ss[i]);
| ^~~~~~~~~~~~~~~~~~
# | 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... |