In the problem 103107G - Go? No, the following code works in C++17 (GCC 7-32)(330101327), but fails in C++20 (GCC 13-64)(330101365) and C++23 (GCC 14-64, msys2) (330101397).
The exit code shows STATUS_STACK_OVERFLOW, but according to this, there should be enough stack space. I wonder if I did anything wrong or there's some problem with C++20,23?
Any insights or assistance would be greatly appreciated.
Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
char s[N][N];
int n,m;
inline int T(int x,int y){return x*m+y;}
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int max_cc = -1000;
int low[N][N],dfn[N][N],tot;
void tarjan(int ux,int uy,bool is_root){
low[ux][uy]=dfn[ux][uy]=++tot;
int cnt = 0;
int ch = 0;
for(int k=0;k<4;k++){
int vx=ux+dx[k],vy=uy+dy[k];
if(vx<0||vx>=n||vy<0||vy>=m)continue;
if(s[vx][vy]=='#')continue;
if(!dfn[vx][vy]){
tarjan(vx,vy,0);
low[ux][uy]=min(low[ux][uy],low[vx][vy]);
if(low[vx][vy]>=dfn[ux][uy])cnt++;
ch++;
}
else{
low[ux][uy]=min(low[ux][uy],dfn[vx][vy]);
}
}
if(is_root) max_cc=max(max_cc,ch-1);
else max_cc=max(max_cc,cnt);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>s[i];
int all=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s[i][j]!='.')continue;
if(!dfn[i][j]){
all++;
tarjan(i,j,1);
}
}
}
cout << max_cc + all << '\n';
return 0;
}







