Submission #922635

#TimeUsernameProblemLanguageResultExecution timeMemory
922635rainboyTrucks (LMIO17_sunkvezimiai)C11
100 / 100
136 ms12880 KiB
#include <stdio.h> #include <string.h> #define N 200000 #define M 200000 unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int ii[M], jj[M], ww[M]; void sort(int *hh, int l, int r) { while (l < r) { int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp; while (j < k) if (ww[hh[j]] == ww[h]) j++; else if (ww[hh[j]] < ww[h]) { tmp = hh[i], hh[i] = hh[j], hh[j] = tmp; i++, j++; } else { k--; tmp = hh[j], hh[j] = hh[k], hh[k] = tmp; } sort(hh, l, i); l = k; } } int ds[N], ww_[N]; int find(int i) { return ds[i] < 0 ? i : find(ds[i]); } void join(int i, int j, int w) { i = find(i); j = find(j); if (i == j) return; if (ds[i] > ds[j]) ds[i] = j, ww_[i] = w; else { if (ds[i] == ds[j]) ds[i]--; ds[j] = i, ww_[j] = w; } } int query(int i, int j) { int w = 0; while (i != j && i >= 0 && j >= 0) if (ww_[i] < ww_[j]) w = ww_[i], i = ds[i]; else w = ww_[j], j = ds[j]; return w; } int main() { static int hh[M]; int n, m, q, h, h_, i, j, w; scanf("%d%d%d", &n, &m, &q); for (h = 0; h < m; h++) scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--; for (h = 0; h < m; h++) hh[h] = h; sort(hh, 0, m); memset(ds, -1, n * sizeof *ds), memset(ww_, 0x3f, n * sizeof *ww_); for (h = 0; h < m; h++) { h_ = hh[h]; join(ii[h_], jj[h_], ww[h_]); } while (q--) { scanf("%d%d%d", &i, &j, &w), i--, j--; printf(query(i, j) <= w ? "TAIP\n" : "NE\n"); } return 0; }

Compilation message (stderr)

sunkvezimiai.c: In function 'main':
sunkvezimiai.c:69:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d%d%d", &n, &m, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sunkvezimiai.c:71:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d%d%d", &ii[h], &jj[h], &ww[h]), ii[h]--, jj[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sunkvezimiai.c:81:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   scanf("%d%d%d", &i, &j, &w), 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...