Submission #1003176

#TimeUsernameProblemLanguageResultExecution timeMemory
1003176vjudge1Pipes (CEOI15_pipes)C++17
40 / 100
714 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' //#define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } struct Dsu{ // 0 - indexed vector <int> fa; Dsu(int m){ fa.resize(m); for ( int i = 0; i < m; i++ ){ fa[i] = i; } } int get(int x){ return (x == fa[x] ? x : fa[x] = get(fa[x])); } bool merge(int u, int v){ u = get(u), v = get(v); if ( u == v ){ return false; } fa[v] = u; return true; } bool same(int u, int v){ return get(u) == get(v); } }; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector <vector<int>> adj(n); Dsu ds1(n), ds2(n); for ( int i = 0; i < m; i++ ){ int u, v; cin >> u >> v; --u, --v; if ( ds1.merge(u, v) || ds2.merge(u, v) ){ adj[u].pb(v); adj[v].pb(u); } } vector <int> tin(n), low(n); int ct = 0; auto dfs = [&](auto dfs, int u, int p) -> void{ tin[u] = low[u] = ++ct; bool flag = false; for ( auto &v: adj[u] ){ if ( v == p && !flag ){ flag = true; continue; } if ( !tin[v] ){ dfs(dfs, v, u); chmin(low[u], low[v]); if ( low[v] > tin[u] ){ cout << u + 1 << ' ' << v + 1 << ln; } } else{ chmin(low[u], tin[v]); } } }; for ( int i = 0; i < n; i++ ){ if ( !tin[i] ){ dfs(dfs, i, -1); } } cout << '\n'; }
#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...