#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> p1(100001,-1);
vector<int> p2(100001,-1);
vector<bool> vis;
vector<pair<int,int> > vk;
vector<vector<int> > v;
vector<int> rednibroj;
int edges=0;
int broj=1;
int dsu1(int x)
{
int px=x;
while(p1[x]!=-1)
x=p1[x];
int y=x;
while(px!=y)
{
int xx=p1[px];
p1[px]=y,px=xx;
}
return x;
}
int dsu2(int x)
{
int px=x;
while(p2[x]!=-1)
x=p2[x];
int y=x;
while(px!=y)
{
int xx=p2[px];
p2[px]=y,px=xx;
}
return x;
}
int bridges(int x,int prev,int broj)
{
rednibroj[x]=broj;
int minbr=broj;
int maxi=0;
int granki=0;
for(int i=0;i<v[x].size();i++)
{
if(v[x][i]==prev)
continue;
if(rednibroj[v[x][i]])
minbr=min(minbr,rednibroj[v[x][i]]);
else
{
int t=bridges(v[x][i],x,broj+1);
maxi=max(maxi,t);
minbr=min(minbr,t);
granki++;
}
}
if(maxi>=rednibroj[x])
{
if(x>=edges)
vis[x-edges]=true;
}
return minbr;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
a--;
b--;
int x=dsu1(a);
int y=dsu1(b);
if(x!=y)
{
p1[x]=y;
vk.push_back(make_pair(a,b));
vis.push_back(0);
edges++;
}
else
{
int x1=dsu2(a);
int y1=dsu2(b);
if(x1!=y1)
{
p2[x1]=y1;
vk.push_back(make_pair(a,b));
vis.push_back(0);
edges++;
}
}
}
p1.clear();
p2.clear();
vector<int> vec;
v.insert(v.begin(),n+edges+2,vec);
for(int i=0;i<n+edges+3;i++)
{
rednibroj.push_back(0);
}
int br=edges;
for(int i=0;i<edges;i++)
{
pair<int,int> p=vk[i];
v[p.first].push_back(br);
v[br].push_back(p.first);
v[br].push_back(p.second);
v[p.second].push_back(br);
br++;
}
for(int i=0;i<n;i++)
{
if(!rednibroj[i])
{
bridges(i,-1,1);
}
}
for(int i=0;i<edges;i++)
{
if(vis[i])
{
cout<<vk[i].first+1<<" "<<vk[i].second+1<<endl;
}
}
return 0;
}
Compilation message
pipes.cpp: In function 'int bridges(int, int, int)':
pipes.cpp:45:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].size();i++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
2276 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
3512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
3220 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
177 ms |
5184 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
304 ms |
9524 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
415 ms |
24036 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
638 ms |
27280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
854 ms |
33092 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1124 ms |
33144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1301 ms |
31584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |