Submission #1085986

# Submission time Handle Problem Language Result Execution time Memory
1085986 2024-09-09T08:54:33 Z juicy Pipes (CEOI15_pipes) C++17
40 / 100
727 ms 56668 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e5;

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];

void add(int u, int 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 + 1 << " " << v + 1 << "\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; --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 3416 KB Output is correct
2 Correct 1 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3932 KB Output is correct
2 Correct 3 ms 3864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 6872 KB Output is correct
2 Correct 57 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 9476 KB Output is correct
2 Correct 122 ms 9796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 14416 KB Output is correct
2 Runtime error 160 ms 19396 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 258 ms 21328 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 384 ms 28888 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 495 ms 36440 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 609 ms 44112 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 727 ms 56668 KB Memory limit exceeded
2 Halted 0 ms 0 KB -