#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define em emplace
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int MAX = 100010;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
struct UFT {
int p[MAX];
UFT(int n) {
for(int i = 1; i <= n; i++) p[i] = i;
}
int find(int x) {
return p[x] == x ? p[x] : p[x] = find(p[x]);
}
void uni(int x, int y) {
x = find(x), y = find(y);
p[max(x, y)] = min(x, y);
}
};
vector <int> g[MAX];
int low[MAX], ord[MAX], cnt = 0;
void dfs(int x, int pa) {
ord[x] = low[x] = ++cnt;
for(auto i : g[x]) {
if(i == pa) continue;
if(ord[i] == 0) {
dfs(i, x);
low[x] = min(low[x], low[i]);
if(low[i] > ord[x]) cout << x << ' ' << i << '\n';
}
else if(ord[i] < ord[x]) {
low[x] = min(low[x], ord[i]);
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int n, m;
cin >> n >> m;
UFT t1(n), t2(n);
for(int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
if(t1.find(u) != t1.find(v)) {
t1.uni(u, v);
g[u].eb(v), g[v].eb(u);
}
else if(t2.find(u) != t2.find(v)) {
t2.uni(u, v);
g[u].eb(v), g[v].eb(u);
}
}
for(int i = 1; i <= n; i++) {
if(ord[i] == 0) dfs(i, 0);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Incorrect |
4 ms |
2680 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
3192 KB |
Output is correct |
2 |
Incorrect |
8 ms |
2936 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
3048 KB |
Output is correct |
2 |
Incorrect |
128 ms |
2908 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
222 ms |
3832 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
5420 KB |
Output is correct |
2 |
Runtime error |
315 ms |
18956 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
480 ms |
10716 KB |
Output is correct |
2 |
Runtime error |
428 ms |
25336 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
11904 KB |
Output is correct |
2 |
Runtime error |
733 ms |
42488 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1000 ms |
14136 KB |
Output is correct |
2 |
Runtime error |
923 ms |
50604 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1284 ms |
18432 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1506 ms |
30652 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |
2 |
Halted |
0 ms |
0 KB |
- |