rt,在洛谷在线ide上和该题-P5058上只能使用c++98才能编译。
#include<bits/stdc++.h>
using namespace std;
/*2024/7/5
*question id:p5058
*answer:
*idea:
*else:
*/
const int maxn=2000105;
struct Edge{
int now=-1,next=-1;
}edges[maxn*5];
int nodes[maxn],dfn[maxn],low[maxn];
int n,x,y,root=0,cnt=0,Time=0;
set<int> st;
inline void add(int x,int y){
edges[++cnt].now=y;
edges[cnt].next=nodes[x];
nodes[x]=cnt;
return;
}
inline void tarjan(int np,int fa){
int cutcnt=0;
dfn[np]=low[np]=++Time;
for(int i=nodes[np];i;i=edges[i].next){
int Next=edges[i].now;
if(Next==fa)continue;
if(!dfn[Next]){
tarjan(Next,np);
low[np]=min(low[np],low[Next]);
if(dfn[np]<=low[Next]&&(++cutcnt>=2||np!=root)){
if(dfn[Next]<=dfn[y])st.insert(np);
}
}
else low[np]=min(low[np],dfn[Next]);
}
return;
}
int main(){
scanf("%d",&n);
while(true){
scanf("%d%d",&x,&y);
if(x==0&&y==0)break;
add(x,y);
add(y,x);
}
scanf("%d%d",&x,&y);
root=x;
tarjan(x,0);
if(st.size()==0)printf("No solution\n");
else printf("%d\n",*st.begin());
return 0;
}
5
2 1
2 5
1 4
5 3
2 3
5 1
0 0
4 2
1
而在Dev-c++上就没问题,本蒟蒻已经遇到两次了,求大佬解惑QAQ。