Title: https://www.luogu.org/problemnew/show/P1119
Floyd's naked question... Besides, the completion time of each point and the time in the query are monotonous.
If Q times djkstra, the access process is based on the t of edge[i].to to judge whether you can go...don't care.
Before Floyd, although it was not built well when t=0, it was necessary to assign the edge weight to the initial value, and when using other k, it was still necessary to update the points that were not built; it was just a judgment when outputting.
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std; const int N=205,M=200*199/2+5; const ll INF=795741901218843403; int n,m,q,t[N],cur; ll f[N][N]; intmain () { memset(f,11,sizeof f); scanf("%d%d",&n,&m);int x,y,z; for(int i=0;i<n;i++)scanf("%d",&t[i]); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); f[x][y]=f[y][x]=z;// } scanf("%d",&q);cur=-1; while(q--) { scanf("%d%d%d",&x,&y,&z); while(1) { if(t[cur+1]>z||cur+1>n)break;cur++; for(int i=0;i<n;i++) for(int j=0;j<n;j++) f[i][j]=min(f[i][j],f[i][cur]+f[cur][j]); } if(t[x]>z||t[y]>z||f[x][y]==INF)printf("-1\n"); else printf("%lld\n",f[x][y]); } return 0; }