# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
379889 |
2021-03-19T15:50:30 Z |
soroush |
Pipes (CEOI15_pipes) |
C++17 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1;
#define pb push_back
#define endl '\n'
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int par1[maxn] , par2[maxn];
vector < int > adj[maxn];
int n , m;
int getpar(int v , int *par){
return((par[v]) ? par[v] = getpar(par[v] , par) : v);
}
void merge(int v , int u){
if(getpar(u , par1) ^ getpar(v , par1))
par1[getpar(u , par1)] = getpar(v , par1);
else if(getpar(u , par2) ^ getpar(v , par2))
par2[getpar(u , par2)] = getpar(v , par2);
else
return;
adj[u].pb(v);
adj[v].pb(u);
}
int par[maxn] , h[maxn] , cnt[maxn];
void dfs(int v){
h[v] = h[par[v]] + 1;
par1[v] = par2[v] = h[v];
for(auto u : adj[v])if(u^par[v]){
if(!par2[u])
par[u] = v , dfs(u) , par1[v] = min(par1[v] , par1[u]);
else
par1[v] = min(par1[v] , par2[u]);
}else cnt[v];
if(par1[v] == h[v] and par[v] and cnt[v] == 1)
cout << v << ' ' << p << endl;
}
int32_t main(){
migmig;
cin >> n >> m;
for(int i = 1 ; i <= m ; i ++){
int u , v;
cin >> u >> v;
merge(u , v);
}
for(int i = 1 ; i <= n ; i ++)par2[i] = 0;
for(int i = 1 ; i <= n ; i ++)if(!par2[i])dfs(i);
return(0);
}
Compilation message
pipes.cpp: In function 'void dfs(int)':
pipes.cpp:40:13: warning: statement has no effect [-Wunused-value]
40 | }else cnt[v];
| ~~~~~^
pipes.cpp:42:23: error: 'p' was not declared in this scope
42 | cout << v << ' ' << p << endl;
| ^