# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
478972 |
2021-10-09T09:25:12 Z |
hjc4vr |
Pipes (CEOI15_pipes) |
C++14 |
|
1264 ms |
14864 KB |
#include <bits/stdc++.h>
using namespace std;
int ufds1[100005],ufds2[100005],low[100005],depths[100005];
vector<int> adj[100005];
int find(int a,int par[]){
if (par[a]==a) return a;
par[a] = find(par[a],par);
return par[a];
}
void dfs(int cur,int par){
depths[cur] = depths[par] + 1;
low[cur] = depths[cur];
bool check= false;
for (auto it: adj[cur]){
if (check == false && it==par){
check = true;
continue;
}
else{
if (depths[it]==-1){
dfs(it,cur);
low[cur] = min(low[cur],low[it]);
if (low[it]>depths[cur]){
cout << cur << ' ' << it << '\n';
}
}else{
low[cur] = min(low[cur],depths[it]);
}
}
}
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
fill(depths,depths+100005,-1);
for (int i=1;i<=n;++i){
ufds1[i] = i;
ufds2[i] = i;
}
for (int i=0;i<m;++i){
int a,b;cin>>a>>b;
int pa = find(a,ufds1), pb = find(b,ufds1);
if (pa!=pb){
adj[a].push_back(b);
adj[b].push_back(a);
ufds1[pb] = pa;
}else{ // it is a back edge
int ba = find(a,ufds2), bb = find(b,ufds2);
if (ba!=bb){
adj[a].push_back(b);
adj[b].push_back(a);
ufds2[bb] = ba;
}
}
}
for (int i=1;i<=n;++i){
if (depths[i]==-1){
dfs(i,0);
}
}
}
//
//4
//4
//2
//2
//2
//4
//4
//4
//4
//2
//4
//4
//2
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3548 KB |
Output is correct |
2 |
Correct |
7 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
3368 KB |
Output is correct |
2 |
Correct |
104 ms |
3212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
4156 KB |
Output is correct |
2 |
Correct |
217 ms |
3628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
290 ms |
5860 KB |
Output is correct |
2 |
Correct |
268 ms |
5416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
392 ms |
11412 KB |
Output is correct |
2 |
Correct |
368 ms |
7368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
615 ms |
12556 KB |
Output is correct |
2 |
Correct |
738 ms |
9292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
821 ms |
14864 KB |
Output is correct |
2 |
Correct |
780 ms |
9128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
977 ms |
14864 KB |
Output is correct |
2 |
Correct |
924 ms |
9204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1227 ms |
14232 KB |
Output is correct |
2 |
Correct |
1264 ms |
11156 KB |
Output is correct |