下面这个代码TLE了5个点,但是在本地运行没有TLE
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int n,e,c,m,d[N];
int tot;
int head[N],nxt[N];
struct edge{
int from,to;
}g[N];
inline void add(int u,int v){
d[u]++;
tot++;
g[tot].from=u;
g[tot].to=v;
nxt[tot]=head[u];
head[u]=tot;
}
int step[N][N];
int vis[N],dis[N];
inline void calc_step(int pos){
memset(vis,false,sizeof(vis));
memset(dis,0x3f,sizeof(dis));
queue<int> q;
vis[pos]=true;
dis[pos]=0;
q.push(pos);
while(!q.empty()){
int u=q.front(); q.pop();
for(int v=head[u];v;v=nxt[v]){
int to=g[v].to;
if(!vis[to]&&dis[to]>dis[u]+1){
dis[to]=dis[u]+1;
vis[to]=true;
step[to][pos]=u;
q.push(to);
}else{
if(dis[to]==dis[u]+1&&u<step[to][pos]) step[to][pos]=u;
}
}
}
}
double cache[N][N];
bool mem[N][N];
inline double p(int x,int y){
if(x==y) return 0.0;
if(step[x][y]==y||step[step[x][y]][y]==y) return 1.0;
if(mem[x][y]) return cache[x][y];
double ret=p(step[step[x][y]][y],y);
for(int v=head[y];v;v=nxt[v]) ret+=p(step[step[x][y]][y],g[v].to);
mem[x][y]=true;
return cache[x][y]=1.0+ret/(d[y]+1.0);
}
int main(){
cin>>n>>e>>c>>m;
for(int i=1,u,v;i<=e;i++){
cin>>u>>v;
add(u,v),add(v,u);
}
for(int i=1;i<=n;i++) calc_step(i);
cout<<fixed<<setprecision(3)<<p(c,m);
return 0;
}