#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define pll pair<ll , ll >
#define all(x) (x).begin(),(x).end()
#define SZ(x) (ll)(x).size()
#define X first
#define Y second
#define mp make_pair
#define pii pair<int , int>
#define vec vector
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
ll poww(ll a, ll b, ll md) {
return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;
const ll mod = 1e9 + 7 ;
const int lg = 20 ;
int n , m , par[2][maxn] , sz[2][maxn] , dp[maxn] , p[maxn] , mark[maxn] , h[maxn];
vec<int> adj[maxn] ;
void prep(){
for(int i = 1 ; i <= n ; i ++ ){
par[0][i] = par[1][i] = i ;
sz[0][i] = sz[1][i] = 1 ;
}
}
vec<pii> e ;
int getpar(int k , int v){
return par[k][v] == v ? v : par[k][v] = getpar(k , par[k][v]) ;
}
bool merge(int k , int x , int y){
x = getpar(k , x) ;y = getpar(k , y) ;
if(x == y) return false ;
if(sz[k][x] < sz[k][y]) swap(x , y) ;
sz[k][x] += sz[k][y] ;
par[k][y] = x ;
return true ;
}
void dfs(int v){
mark[v] = 1 ;
for(auto u : adj[v]){
if(!mark[u]){
p[u] = v ;
h[u] = h[v] + 1 ;
dfs(u) ;
dp[v] = min(dp[v] , dp[u]) ;
}else{
if(u != p[v]){
dp[v] = min(dp[v] , h[u]) ;
}
}
}
if(p[v] != 0 && dp[v] >= h[p[v]]){
cout<<v <<" " << p[v] << endl ;
}
dp[v] = min(dp[v] , h[p[v]] ) ;
}
int main()
{
migmig ;
h[0] = mod ;
cin>>n>>m ;
prep() ;
int u , v ;
for(int i =1 ; i <= m ; i ++ ){
cin>>u>>v ;
if(!merge(0 , u , v)){
if(merge(1 , u , v)){
adj[u].pb(v) ;
adj[v].pb(u) ;
}
}else{
adj[v].pb(u) ;
adj[u].pb(v) ;
}
}
memset(dp , 63 , sizeof dp) ;
for(int i = 1 ; i <= n ; i ++ ){
if(!mark[i]){
dfs(i) ;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3052 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
3692 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
114 ms |
3564 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
191 ms |
4460 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
328 ms |
6124 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
435 ms |
11884 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
675 ms |
13164 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
880 ms |
15648 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1099 ms |
15724 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1315 ms |
14956 KB |
Wrong number of edges |
2 |
Halted |
0 ms |
0 KB |
- |