# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
379893 |
2021-03-19T15:51:40 Z |
soroush |
Pipes (CEOI15_pipes) |
C++17 |
|
1345 ms |
14572 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 << ' ' << par[v] << 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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3180 KB |
Output is correct |
2 |
Correct |
7 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
3052 KB |
Output is correct |
2 |
Correct |
110 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
3864 KB |
Output is correct |
2 |
Correct |
216 ms |
3308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
5436 KB |
Output is correct |
2 |
Correct |
284 ms |
5228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
10988 KB |
Output is correct |
2 |
Correct |
404 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
684 ms |
12268 KB |
Output is correct |
2 |
Correct |
681 ms |
9324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
907 ms |
14572 KB |
Output is correct |
2 |
Correct |
847 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1149 ms |
14444 KB |
Output is correct |
2 |
Correct |
1043 ms |
9452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1319 ms |
13912 KB |
Output is correct |
2 |
Correct |
1345 ms |
11244 KB |
Output is correct |