#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long dfn[100001],low[1000001],jl;
long long head[100001],next[100001];
long long jk[100001],ans=1;
long long l;
bool br[100001];
struct bit{
long long x,y;
}o[100001];
bool cmp(const bit a,const bit b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
void add(long long x,long long y) {
jk[++ans]=y,next[ans]=head[x],head[x]=ans;
return;
}
void Tarjian(long long x,long long k)
{
dfn[x]=low[x]=++jl;
for(long long i=head[x];i;i=next[i]){
long long y=jk[i];
if(!dfn[y]){
Tarjian(y,i);
low[x]=min(low[x],low[y]);
if(low[y]>dfn[x]) br[i]=br[i^1]=1;
}
else if(i!=(k^1)) low[x]=min(low[x],dfn[y]);
}
return;
}
int main()
{
std::cin.tie(0);
std::cout.tie(0);
cin>>n>>m;
for(long long i=1;i<=m;i++){
long long x,y;
cin>>x>>y;
add(x,y);//单向边
add(y,x);//双向边
}
for(long long i=1;i<=n;i++)
if(!dfn[i]) Tarjian(i,0);
for(long long i=2;i<=ans;i++){
if(br[i]==1){
l++;
o[l].x=min(jk[i^1],jk[i]);
o[l].y=max(jk[i^1],jk[i]);
}
}
std::sort(o+1,o+l+1,cmp);
for(long long i=1;i<=l;i++){
if(o[i].x==o[i+1].x){
if(o[i].y==o[i+1].y){
continue;
}
else cout<<o[i].x<<" "<<o[i].y<<"\n";
}
else cout<<o[i].x<<" "<<o[i].y<<"\n";
}
return 0;
}
luogu编译失败原因:
/tmp/compiler_zwwyetrp/src: 在函数‘void add(long long int, long long int)’中:
/tmp/compiler_zwwyetrp/src:20:17: 错误:对‘next’的引用有歧义
20 |
jk[++ans]=y,next[ans]=head[x],head[x]=ans;
| ^~~~
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_algobase.h:66,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/char_traits.h:39,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ios:40,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/istream:38,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/sstream:38,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/complex:45,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ccomplex:39,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:54,
from /tmp/compiler_zwwyetrp/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_iterator_base_funcs.h:213:5: 附注:备选为: ‘template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)’
213 | next(_InputIterator __x, typename
| ^~~~
/tmp/compiler_zwwyetrp/src:5:24: 附注: ‘long long int next [100001]’
5 | long long head[100001],next[100001];
| ^~~~
/tmp/compiler_zwwyetrp/src: 在函数‘void Tarjian(long long int, long long int)’中:
/tmp/compiler_zwwyetrp/src:27:30: 错误:对‘next’的引用有歧义
27 | for(long long i=head[x];i;i=next[i]){
| ^~~~
In file included from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_algobase.h:66,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/char_traits.h:39,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ios:40,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/istream:38,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/sstream:38,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/complex:45,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/ccomplex:39,
from /nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/stdc++.h:54,
from /tmp/compiler_zwwyetrp/src:1:
/nix/store/bbmwawbq7wjb54fa35wr72alcm083d1f-luogu-gcc-9.3.0/include/c++/9.3.0/bits/stl_iterator_base_funcs.h:213:5: 附注:备选为: ‘template<class _InputIterator> _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)’
213 | next(_InputIterator __x, typename
| ^~~~
/tmp/compiler_zwwyetrp/src:5:24: 附注: ‘long long int next [100001]’
5 | long long head[100001],next[100001];
| ^~~~