#include <iostream>
#include <vector>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 1e5+5;
int N, M;
vector<int> al[mxN];
struct UFDS {
int p[mxN], s[mxN];
UFDS() { FOR(i,1,N) p[i] = i, s[i] = 1; }
int finds(int i) { return (p[i] == i) ? i : (p[i] = finds(p[i])); }
bool unions(int i, int j) {
int x = finds(i), y = finds(j);
if (x == y) return 0;
if (s[x] < s[y]) swap(x,y);
p[y] = x, s[x] += s[y];
return 1;
}
};
int num[mxN], low[mxN], cnt;
void dfs(int u, int p) {
num[u] = low[u] = cnt++;
for (int v : al[u]) {
if (v == p) continue;
else if (num[v] == -1) {
dfs(v,u);
low[u] = min(low[u],low[v]);
if (low[v] > num[u]) cout << u << ' ' << v << '\n';
} else low[u] = min(low[u],num[v]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
UFDS UF[2];
FOR(i,1,M){
int U, V; cin >> U >> V;
FOR(j,0,1){
if (UF[j].unions(U,V)) {
al[U].push_back(V);
al[V].push_back(U);
break;
}
}
}
FOR(i,1,N) num[i] = -1;
cnt = 0;
FOR(i,1,N) if (num[i] == -1) dfs(i,0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
6 ms |
2688 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
3328 KB |
Output is correct |
2 |
Incorrect |
9 ms |
3200 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
8672 KB |
Output is correct |
2 |
Incorrect |
104 ms |
8312 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
167 ms |
13536 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
329 ms |
19704 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 |
Correct |
436 ms |
14328 KB |
Output is correct |
2 |
Incorrect |
387 ms |
16120 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
681 ms |
13564 KB |
Output is correct |
2 |
Incorrect |
665 ms |
11896 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
912 ms |
21904 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 |
Correct |
1154 ms |
16376 KB |
Output is correct |
2 |
Incorrect |
1068 ms |
15096 KB |
Wrong number of edges |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1386 ms |
15864 KB |
Output is correct |
2 |
Runtime error |
1327 ms |
27256 KB |
Memory limit exceeded (if you are sure your verdict is not MLE, please contact us) |