Submission #1034673

#TimeUsernameProblemLanguageResultExecution timeMemory
1034673vjudge1Pipes (CEOI15_pipes)C++17
0 / 100
759 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; template<class T> bool chmin(T& a, const T& b) { return b<a?a=b, 1:0; } template<class T> bool chmax(T& a, const T& b) { return a<b?a=b, 1:0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); /** * Author: Lukas Polacek * Date: 2009-10-26 * License: CC0 * Source: folklore * Description: Disjoint-set data structure. * Time: $O(\alpha(N))$ */ struct UF { vi e; UF(int n) : e(n, -1) {} bool sameSet(int a, int b) { return find(a) == find(b); } int size(int x) { return -e[find(x)]; } int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); } bool join(int a, int b) { a = find(a), b = find(b); if (a == b) return false; if (e[a] > e[b]) swap(a, b); e[a] += e[b]; e[b] = a; return true; } }; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, m; cin >> n >> m; vt<pii> e; int u, v; UF d1(n+1), d2(n+1); vt<vt<int>> g(n+1); rep(i, 0, m) { cin >> u >> v; if(d1.join(u, v)) { g[u].pb(v); g[v].pb(u); } else if(d2.join(u, v)) { g[u].pb(v); g[v].pb(u); } } vt<int> low(n+1), id(n+1); int timer=0; bool ck=0; auto dfs = [&](int at, int par, auto &&self) -> void { ck=0; id[at]=low[at]=++timer; for(auto to:g[at]) { if(to == par and ck==0) { ck=1; continue; } if(id[to]) { low[at]=min(low[at], id[to]); } else { self(to, at, self); low[at]=min(low[at], low[to]); } } if(low[at] == id[at] and at!=par) { cout << at << " " << par << "\n"; } }; for(int i= 1;i<=n;i++) { if(!id[i]) dfs(i, i, dfs); } }
#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...