Submission #1085991

# Submission time Handle Problem Language Result Execution time Memory
1085991 2024-09-09T08:59:21 Z juicy Pipes (CEOI15_pipes) C++17
100 / 100
714 ms 14084 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];
 
  int find(int u) {
    return !pr[u] ? 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 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3164 KB Output is correct
2 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 3156 KB Output is correct
2 Correct 54 ms 2980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 3664 KB Output is correct
2 Correct 108 ms 3248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 5460 KB Output is correct
2 Correct 142 ms 4916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 229 ms 10576 KB Output is correct
2 Correct 204 ms 7164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 356 ms 11864 KB Output is correct
2 Correct 357 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 468 ms 13976 KB Output is correct
2 Correct 447 ms 9292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 611 ms 14084 KB Output is correct
2 Correct 548 ms 9044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 714 ms 13392 KB Output is correct
2 Correct 674 ms 10580 KB Output is correct