Submission #100617

#TimeUsernameProblemLanguageResultExecution timeMemory
100617dooweyPipes (CEOI15_pipes)C++14
90 / 100
1125 ms11860 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)1e5 + 9; struct DSU{ int pi[N]; void Init(){ for(int i = 0 ; i < N; i ++ ) pi[i] = i; } int fin(int node){ if(node == pi[node]) return node; return pi[node] = fin(pi[node]); } bool unite(int a, int b){ a = fin(a); b = fin(b); if(a==b) return false; pi[a] = b; return true; } }; DSU A, B; // all this memory bullsh*t int nod[N * 4]; int prv[N * 4]; int tin[N]; int las[N]; int p; void init(){ for(int i =0 ; i < N; i ++ ) las[i] = -1, tin[i] = -1; for(int i = 0 ;i < N * 4 ;i ++ ) prv[i] = -1, nod[i] = -1; } void addedg(int a, int b){ prv[p] = las[a]; nod[p] = b; las[a] = p; p ++ ; } void EDGE(int a, int b){ addedg(a, b); addedg(b, a); } int low[N]; int timer; void dfs(int node, int par){ tin[node] = timer ++ ; low[node] = tin[node]; for(int i = las[node]; i != -1; i = prv[i]){ if(nod[i] == par) continue; if(tin[nod[i]] != -1){ low[node] = min(low[node], tin[nod[i]]); } else{ dfs(nod[i], node); low[node] = min(low[node], low[nod[i]]); if(tin[node] < low[nod[i]] && B.fin(nod[i]) != B.fin(node)){ cout << node << " " << nod[i] << "\n"; } } } } int main(){ fastIO; init(); A.Init(); B.Init(); int n, m; cin >> n >> m; int u, v; for(int i =0 ; i < m ; i ++ ){ cin >> u >> v; if(A.unite(u,v)){ EDGE(u,v); } else if(B.unite(u, v)){ EDGE(u,v); } } dfs(1,-1); return 0; }
#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...