简单的spfa。。
但我就纳闷了,为啥数组模拟邻接表却tle#include#include using namespace std;int du[99999];int flag[2999];double dis[2099];int w[2989][2999];int n,m;int main(){ int x,y,z; scanf("%d%d",&n,&m); memset(dis,127,sizeof(dis)); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); w[x][y]=100-z; w[y][x]=100-z; } scanf("%d%d",&x,&y); int head=0,tail=1; du[1]=y; flag[y]=1; dis[y]=100; do { head++; int t=du[head]; flag[t]=0; for(int i=1;i<=n;i++) if(w[t][i]) { if(dis[i]>dis[t]/(w[t][i])*100) { dis[i]=dis[t]/(w[t][i])*100; if(!flag[i]) { du[++tail]=i; flag[i]=1; } } } }while(head