Submission #100625

#TimeUsernameProblemLanguageResultExecution timeMemory
100625dooweyPipes (CEOI15_pipes)C++14
100 / 100
3987 ms8696 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+1; int n1[N], n2[N]; int tin[N], low[N]; int nd[4 * N], pv[4 * N]; int las[N]; int timer; int cnt; void add(int a, int b){ // a -> b nd[cnt]=b; pv[cnt]=las[a]; las[a]=cnt; cnt ++ ; } void EDGE(int a, int b){ add(a,b); add(b,a); } int fin1(int x){ if(n1[x] == x) return x; return n1[x]=fin1(n1[x]); } int fin2(int x){ if(n2[x] == x) return x; return n2[x]=fin2(n2[x]); } bool merg1(int a, int b){ a=fin1(a); b=fin1(b); if(a==b) return false; n1[a]=b; return true; } bool merg2(int a, int b){ a=fin2(a); b=fin2(b); if(a==b) return false; n2[a]=b; return true; } void Init(){ for(int i = 0 ; i < N ; i ++ ){ n1[i] = i, n2[i] = i; tin[i] = -1, low[i] = -1; las[i] = -1; } for(int i = 0 ; i < 4 * N ; i ++ ){ nd[i] = -1; pv[i] = -1; } } void dfs(int node, int par){ tin[node] = timer ++ ; low[node] = tin[node]; for(int j = las[node] ; j != -1 ; j = pv[j]){ if(nd[j] == par){ continue; } if(tin[nd[j]] != -1){ low[node] = min(low[node], tin[nd[j]]); } else{ dfs(nd[j], node); low[node] = min(low[node], low[nd[j]]); if(tin[node] < low[nd[j]] && fin2(node) != fin2(nd[j])){ cout << node << " " << nd[j] << "\n"; } } } } int main(){ Init(); int n, m; cin >> n >> m; int u, v; for(int i = 0 ; i < m ; i ++ ){ cin >> u >> v; if(merg1(u,v)) EDGE(u, v); else if(merg2(u,v)) EDGE(u, v); } for(int i =1 ; i <= n; i ++ ) if(tin[i] == -1) dfs(i,-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...