#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 100005;
vector<int> adj[MAXN];
int lab[MAXN][2], numNode, numEdge;
int root(int it, int u) {
return (lab[u][it] == u) ? u : (lab[u][it] = root(it, lab[u][it]));
}
void dfs(int u, int p = -1) {
lab[u][0] = lab[u][1] = ++lab[0][0];
bool edgep(1);
for (int v : adj[u]) {
if(v == p && edgep) {
edgep = 0;
continue;
}
if(!lab[v][1]) {
dfs(v, u);
lab[u][0] = min(lab[u][0], lab[v][0]);
if(lab[v][0] >= lab[v][1])
cout << u << ' ' << v << '\n';
} else {
lab[u][0] = min(lab[u][0], lab[v][1]);
}
}
}
void process() {
cin >> numNode >> numEdge;
for (int i = 1; i <= numNode; ++i)
lab[i][0] = lab[i][1] = i;
for (int i = 0; i < numEdge; ++i) {
int u, v;
cin >> u >> v;
if(root(0, u) != root(0, v)) {
lab[lab[u][0]][0] = lab[v][0];
adj[u].push_back(v);
adj[v].push_back(u);
} else
if(root(1, u) != root(1, v)) {
lab[lab[u][1]][1] = lab[v][1];
adj[u].push_back(v);
adj[v].push_back(u);
}
}
for (int i = 0; i <= numNode; ++i)
lab[i][0] = lab[i][1] = 0;
for (int i = 1; i <= numNode; ++i) {
if(!lab[i][1])
dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3932 KB |
Output is correct |
2 |
Correct |
4 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
3668 KB |
Output is correct |
2 |
Correct |
63 ms |
3572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
4376 KB |
Output is correct |
2 |
Correct |
128 ms |
3844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
5972 KB |
Output is correct |
2 |
Correct |
167 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
11012 KB |
Output is correct |
2 |
Correct |
211 ms |
6908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
390 ms |
12208 KB |
Output is correct |
2 |
Correct |
390 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
512 ms |
14236 KB |
Output is correct |
2 |
Correct |
478 ms |
8368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
621 ms |
14240 KB |
Output is correct |
2 |
Runtime error |
608 ms |
61472 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
829 ms |
13512 KB |
Output is correct |
2 |
Runtime error |
752 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |