Submission #872759

#TimeUsernameProblemLanguageResultExecution timeMemory
872759rainboyExperimental Charges (NOI19_charges)C11
100 / 100
25 ms2588 KiB
#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)

charges.c: In function 'main':
charges.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
charges.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%s%d%d", s, &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...