제출 #527333

#제출 시각아이디문제언어결과실행 시간메모리
527333joelauPipes (CEOI15_pipes)C++14
70 / 100
994 ms17344 KiB
#include <bits/stdc++.h> using namespace std; int N,M, ufds[100005], ufds1[100005], low[100005], depth[100005], p[100005]; vector< pair<int,int> > lst[100005]; int findSet(int i) { return ufds[i] == i ? i : ufds[i] = findSet(ufds[i]); } void unionSet (int i, int j) { int a = findSet(i), b = findSet(j); if (a != b) ufds[a] = b; } int findSet1(int i) { return ufds1[i] == i ? i : ufds1[i] = findSet1(ufds1[i]); } void unionSet1 (int i, int j) { int a = findSet1(i), b = findSet1(j); if (a != b) ufds1[a] = b; } void dfs (int u, int d) { depth[u] = d, low[u] = d; for (auto v: lst[u]) { if (depth[v.first] == -1) { p[v.first] = v.second; dfs(v.first,d+1); if (low[v.first] > depth[u]) cout << u+1 << ' ' << v.first+1 << '\n'; low[u] = min(low[u],low[v.first]); } else if (v.second != p[u]) low[u] = min(low[u],depth[v.first]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M; for (int i = 0; i < N; ++i) ufds[i] = i, ufds1[i] = i; for (int i = 0; i < M; ++i) { int u,v; cin >> u >> v; u--, v--; if (findSet(u) != findSet(v)) { unionSet(u,v); lst[u].emplace_back(v,i), lst[v].emplace_back(u,i); } else if (findSet1(u) != findSet1(v)) { unionSet1(u,v); lst[u].emplace_back(v,i), lst[v].emplace_back(u,i); } } memset(depth,-1,sizeof(depth)); for (int i = 0; i < N; ++i) if (depth[i] == -1) dfs(i,0); 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...