제출 #1034684

#제출 시각아이디문제언어결과실행 시간메모리
1034684vjudge1Pipes (CEOI15_pipes)C++17
40 / 100
762 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()); #pragma GCC optimize("O3,unroll-loops") /** * 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; } }; const int N = 100'010; UF d1(N+1), d2(N+1); vt<int> g[N+1]; int low[N+1], id[N+1]; int timer=0; void dfs(int at, int par) { bool 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 { dfs(to, at); low[at]=min(low[at], low[to]); } } if(low[at] == id[at] and at!=par) { cout << at << " " << par << "\n"; } } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, m; cin >> n >> m; int u, v; 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); } } for(int i= 1;i<=n;i++) { if(!id[i]) dfs(i, i); } }
#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...