Submission #948372

# Submission time Handle Problem Language Result Execution time Memory
948372 2024-03-18T05:01:14 Z vjudge1 Pipes (CEOI15_pipes) C++17
20 / 100
606 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
  return a > b ? (a = b) == b : false;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
  return a < b ? (a = b) == b : false;
}

vector<vector<pair<int, int>>> g;
vector<bool> vis;
vector<int> tin, fup, bridges;
int timer, v, p, idx;
 
void dfs() {
  vis[v] = true;
  tin[v] = fup[v] = ++timer;
  for (auto [to, new_idx] : g[v]) {
    if (idx == new_idx) continue;
    else if (vis[to]) chmin(fup[v], tin[to]);
    else {
      int pv = v, pp = p, pidx = idx;
      v = to, p = v, idx = new_idx;
      dfs();
      v = pv, p = pp, idx = pidx;
      chmin(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        bridges.push_back(new_idx);
      }
    }
  }
}

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m; cin >> n >> m;
  g.resize(n);
  vis.assign(n, false);
  tin.resize(n), fup.resize(n);
  vector<pair<int, int>> vec;
  for (int i = 0; i < m; ++i) {
    int a, b; cin >> a >> b;
    a--, b--;
    g[a].push_back({b, i});
    g[b].push_back({a, i});
    vec.push_back({min(a, b), max(a, b)});
  }
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      v = i, p = -1, idx = -1;
      dfs();
    }
  }
  for (auto i : bridges) {
    cout << vec[i].first + 1 << ' ' << vec[i].second + 1 << '\n';
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1368 KB Output is correct
2 Correct 4 ms 1052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 103 ms 27516 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 35528 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 312 ms 64680 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 581 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 606 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 516 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 579 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 577 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -