제출 #658177

#제출 시각아이디문제언어결과실행 시간메모리
658177blaze21Pipes (CEOI15_pipes)C++17
70 / 100
1453 ms18232 KiB
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <array> #include <queue> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <numeric> #include <cassert> #include <iomanip> using namespace std; #define pi pair<int, int> #define f first #define s second vector <vector <int> > edges (1e5 + 5); vector <bool> visited (1e5 + 5, false); vector <int> tin (1e5 + 5, -1), low (1e5 + 5, -1); int timer = 0; void dfs(int v, int prev){ visited[v] = true; tin[v] = low[v] = timer++; bool ok = false; for(int u : edges[v]){ if(u == prev && !ok){ ok = true; continue; } if(visited[u]){ low[v] = min(low[v], tin[u]); } else{ dfs(u, v); low[v] = min(low[v], low[u]); } } if(prev != -1 && tin[v] == low[v]){ cout << prev << " " << v << endl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector <int> links1 (n + 1), links2 (n + 1), sz1 (n + 1, 1), sz2 (n + 1, 1); iota(links1.begin(), links1.end(), 0); iota(links2.begin(), links2.end(), 0); while(m--){ int a, b, a1, b1, a2, b2; cin >> a >> b; a1 = a2 = a; b1 = b2 = b; while(a1 != links1[a1]){ a1 = links1[a1]; } while(b1 != links1[b1]){ b1 = links1[b1]; } while(a2 != links2[a2]){ a2 = links2[a2]; } while(b2 != links2[b2]){ b2 = links2[b2]; } if(a1 != b1){ edges[a].push_back(b); edges[b].push_back(a); if(sz1[a1] < sz1[b1]){ swap(a1, b1); } links1[b1] = a1; sz1[a1] += sz1[b1]; } else if(a2 != b2){ edges[a].push_back(b); edges[b].push_back(a); if(sz2[a2] < sz2[b2]){ swap(a2, b2); } links2[b2] = a2; sz2[a2] += sz2[b2]; } } for(int i = 1; i <= n; i++){ if(!visited[i]){ dfs(i, -1); } } }
#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...