| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 527217 | siewjh | Pipes (CEOI15_pipes) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 100'005;
vector<int> adjlist[MAXN];
int tvis[MAXN], lo[MAXN];
int cnt = 0;
vector<pair<int, int>> ans;
void dfs(int x, int par) {
tvis[x] = lo[x] = cnt++;
for (auto nxt : adjlist[x]) {
if (nxt == par) continue;
if (tvis[nxt] != INT_MAX) lo[x] = min(lo[x], tvis[nxt]);
else {
dfs(nxt, x);
lo[x] = min(lo[x], lo[nxt]);
if (lo[nxt] > tvis[x]) ans.push_back({ nxt, x });
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int nodes, edges; cin >> nodes >> edges;
for (int i = 0; i < edges; i++) {
int a, b; cin >> a >> b;
adjlist[a].push_back(b);
adjlist[b].push_back(a);
}
for (int i = 1; i <= nodes; i++) tvis[i] = INT_MAX;
for (int i = 1; i <= nodes; i++)
if (tvis[i] == INT_MAX)
dfs(i, -1);
for (auto x : ans) cout << x.first << ' ' << x.second << '\n';
return 0;
}
