Submission #706726

#TimeUsernameProblemLanguageResultExecution timeMemory
706726finn__Pipes (CEOI15_pipes)C++17
0 / 100
1266 ms65536 KiB
#include <bits/stdc++.h> using namespace std; struct Dsu { vector<int> p; Dsu(size_t n) { p = vector<int>(n, -1); } int repr(int u) { return p[u] < 0 ? u : p[u] = repr(p[u]); } bool merge(int i, int j) { i = repr(i); j = repr(j); if (i == j) return 0; if (p[i] > p[j]) swap(i, j); p[i] += p[j]; p[j] = i; return 1; } bool same_set(int i, int j) { return repr(i) == repr(j); } int set_size(int i) { return -p[repr(i)]; } }; constexpr size_t N = 200000; unsigned y[N][2]; int compare_edges(void const *const a, void const *const b) { unsigned u = *(unsigned *)(a), v = *(unsigned *)(b); return u == v ? 0 : (u < v ? -1 : 1); } int main() { size_t n, m, l = 0; scanf("%zu %zu", &n, &m); Dsu d1(n), d2(n); while (m--) { unsigned u, v; scanf("%u %u", &u, &v); u--, v--; if (d1.same_set(u, v)) d2.merge(u, v); else { d1.merge(u, v); y[l][0] = u; y[l][1] = v; l++; y[l][0] = v; y[l][1] = 1; l++; } } qsort(y, l, sizeof *y, compare_edges); for (size_t i = 0; i < l; i++) for (size_t j = i + 1; j < l && y[j][0] == y[i][0]; j++) if (d2.same_set(y[i][1], y[j][1])) d2.merge(y[i][0], y[i][1]); for (size_t i = 0; i < l; i++) if (!d2.same_set(y[i][0], y[i][1]) && y[i][0] < y[i][1]) printf("%u %u\n", y[i][0] + 1, y[i][1] + 1); }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%u %u", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...