//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define X first
#define Y second
typedef pair < int , int > pii;
const int N = 1e5 + 10;
int par[2][N], mark[N], h[N], dp[N];
vector < pii > adj[N];
int getPar(int t, int v){
return par[t][v] == v ? v : par[t][v] = getPar(t, par[t][v]);
}
bool merge(int t, int u, int v){
u = getPar(t, u); v = getPar(t, v);
if (u == v)
return false;
par[t][u] = v;
return true;
}
void DFS(int v, int p = -1){
mark[v] = 1;
dp[v] = N;
for (pii e : adj[v]){
int u = e.X, id = e.Y;
if (id == p)
continue;
if (mark[u])
dp[v] = min(dp[v], h[u]);
else{
h[u] = h[v] + 1;
DFS(u, id);
dp[v] = min(dp[v], dp[u]);
if (h[v] < dp[u])
cout << u << ' ' << v << '\n';
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < N; i ++)
par[0][i] = par[1][i] = i;
for (int i = 0; i < m; i ++){
int u, v;
cin >> u >> v;
if (merge(0, u, v)){
adj[u].pb(mp(v, i));
adj[v].pb(mp(u, i));
}
else if (merge(1, u, v)){
adj[u].pb(mp(v, i));
adj[v].pb(mp(u, i));
}
}
for (int v = 1; v <= n; v ++)
if (!mark[v])
DFS(v);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4204 KB |
Output is correct |
2 |
Correct |
7 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
5812 KB |
Output is correct |
2 |
Correct |
108 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
6764 KB |
Output is correct |
2 |
Correct |
226 ms |
5868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
8300 KB |
Output is correct |
2 |
Runtime error |
291 ms |
19564 KB |
Memory limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
483 ms |
12624 KB |
Output is correct |
2 |
Correct |
401 ms |
10604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
694 ms |
14060 KB |
Output is correct |
2 |
Correct |
648 ms |
12780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
914 ms |
16620 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1126 ms |
16596 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1359 ms |
28012 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |