//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e5 + 10;
int par[2][N], mark[N];
vector < int > 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 = 0){
mark[v] = 1;
par[1][v] = N;
int cnt = 0;
for (int u : adj[v]){
if (u == p){
cnt ++;
continue;
}
if (mark[u])
par[1][v] = min(par[1][v], par[0][u]);
else{
par[0][u] = par[0][v] + 1;
DFS(u, v);
par[1][v] = min(par[1][v], par[1][u]);
}
}
if (p && cnt == 1 && par[0][p] < par[1][v])
cout << p << ' ' << 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(v);
adj[v].pb(u);
}
else if (merge(1, u, v)){
adj[u].pb(v);
adj[v].pb(u);
}
}
memset(par, 0, sizeof par);
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 |
3948 KB |
Output is correct |
2 |
Correct |
8 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
3820 KB |
Output is correct |
2 |
Correct |
109 ms |
3692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
189 ms |
4460 KB |
Output is correct |
2 |
Correct |
222 ms |
3948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
321 ms |
5996 KB |
Output is correct |
2 |
Correct |
274 ms |
5484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
466 ms |
10664 KB |
Output is correct |
2 |
Correct |
403 ms |
7148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
691 ms |
11756 KB |
Output is correct |
2 |
Correct |
635 ms |
8824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
901 ms |
13676 KB |
Output is correct |
2 |
Correct |
856 ms |
14060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1115 ms |
13676 KB |
Output is correct |
2 |
Correct |
1071 ms |
14656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1340 ms |
13164 KB |
Output is correct |
2 |
Runtime error |
1292 ms |
65536 KB |
Memory limit exceeded |