Submission #1085992

# Submission time Handle Problem Language Result Execution time Memory
1085992 2024-09-09T09:00:15 Z juicy Pipes (CEOI15_pipes) C++17
100 / 100
714 ms 13908 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int N = 1e5 + 5;
 
struct dsu {
  int pr[N];
  
  dsu() {
    memset(pr, -1, sizeof(pr));
  }

  int find(int u) {
    return pr[u] < 0 ? u : pr[u] = find(pr[u]);
  }
 
  bool mrg(int u, int v) {
    if ((u = find(u)) == (v = find(v))) {
      return 0;
    }
    pr[v] = u;
    return 1;
  }
} a, b;
 
int n, m;
int low[N], num[N];
vector<int> g[N];
 
#define add(u, v) g[u].push_back(v), g[v].push_back(u)

int timer;
 
void dfs(int u, int p) {
  low[u] = num[u] = ++timer;
  bool flg = 0;
  for (int v : g[u]) {
    if (v == p && !flg) {
      flg = 1;
      continue;
    }
    if (!num[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > num[u]) {
        cout << u << " " << v << "\n";
      }
    } else {
      low[u] = min(low[u], num[v]);
    }
  }
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  cin >> n >> m;
  while (m--) {
    int u, v; cin >> u >> v;
    if (a.mrg(u, v)) {
      add(u, v);
    } else if (b.mrg(u, v)) {
      add(u, v);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!num[i]) {
      dfs(i, i);
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4012 KB Output is correct
2 Correct 4 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 3920 KB Output is correct
2 Correct 53 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 4476 KB Output is correct
2 Correct 112 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 5836 KB Output is correct
2 Correct 144 ms 5592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 10836 KB Output is correct
2 Correct 214 ms 7344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 371 ms 11932 KB Output is correct
2 Correct 355 ms 9336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 481 ms 13908 KB Output is correct
2 Correct 463 ms 9088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 579 ms 13904 KB Output is correct
2 Correct 532 ms 9080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 691 ms 13392 KB Output is correct
2 Correct 714 ms 10504 KB Output is correct