# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994622 |
2024-06-08T02:35:49 Z |
vjudge1 |
Pipes (CEOI15_pipes) |
C++17 |
|
5000 ms |
9308 KB |
#include<bits/stdc++.h>
using namespace std;
#define N 100100
struct unionf{
int par[N];
unionf(){
for(int i=0;i<N;i++)
par[i]=i;
}
int abp(int a){
return (par[a]-a?par[a]=abp(par[a]):a);
}
} cyc,comp;
int par[N],sz[N],dep[N];
set<pair<int,int>>st;
vector<pair<int,int>>adj[N];
void repos(int x,int p,int d){
par[x]=p,dep[x]=d;
for(auto[i,j]:adj[x])
if(cyc.abp(i)-p&&cyc.abp(i)!=x)
repos(cyc.abp(i),x,d+1);
}
int mergepar(int a){
int b=par[a];
dep[a]=dep[b];
par[a]=par[b];
if(adj[a].size()<adj[b].size())
swap(a,b);
vector<pair<int,int>>nadj;
cyc.par[b]=a;
for(auto[i,j]:adj[b]) if(cyc.abp(i)-a)
adj[a].push_back({i,j}),par[i]=a;
adj[b].clear();
return a;
}
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
sz[i]=1;
while(m--){
int a,b;
cin>>a>>b;
if(cyc.abp(a)==cyc.abp(b))
continue;
if(comp.abp(a)==comp.abp(b)){
int acyc=cyc.abp(a),bcyc=cyc.abp(b);
while(acyc-bcyc){
if(dep[acyc]<dep[bcyc])
swap(acyc,bcyc);
acyc=mergepar(acyc),
bcyc=cyc.abp(bcyc);
}
} else {
int acyc=cyc.abp(a),bcyc=cyc.abp(b);
int acomp=comp.abp(a),bcomp=comp.abp(b);
if(sz[acomp]<sz[bcomp]) swap(a,b),
swap(acyc,bcyc),swap(acomp,bcomp);
sz[acomp]+=sz[bcomp];
comp.par[bcomp]=acomp;
repos(bcyc,acyc,dep[acyc]+1);
adj[acyc].push_back({b,a});
adj[bcyc].push_back({a,b});
}
}
for(int i=1;i<=n;i++)if(cyc.abp(i)==i)
for(auto[j,k]:adj[i]) if(cyc.abp(j)-i)
st.insert({min(j,k),max(j,k)});
for(auto[i,j]:st)
cout<<i<<' '<<j<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5047 ms |
4696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
4952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
9308 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5004 ms |
4952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5094 ms |
5208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5033 ms |
5980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5055 ms |
6324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5083 ms |
6488 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5067 ms |
6616 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5027 ms |
6492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |