我寻思我跟某同学都按着同一个框架写的啊,比对细节的话,有差别,但效果都一样
问题来了:为啥他AC而我还过不了样例?
#include<iostream>
#include<cstring>
#define re register
using namespace std;
const int N = 2e4;
int q,n,m,k;
int t[N],dp[N][N];;
inline void cs(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(re int i = 0;i < N;i ++){
for(re int j = 0;j < N;j ++){
dp[i][j] = 99999999;
}
}
}
int main(){
cs();
cin>>n>>m;
for(re int i = 1;i <= n;i ++){
cin>>t[i];
dp[i][i] = 0;
}
for(re int i = 1;i <= m;i ++){
int u,v,w;
cin>>u>>v>>w;
dp[u][v] = w;
dp[v][u] = w;
}
cin>>q;
while(q --){
int x,y,z;
cin>>x>>y>>z;
if(t[x] > z || t[y] > z){
cout<<-1<<"\n";
continue;
}
while(k < n && t[k] <= z){
for(re int i = 1;i <= n;i ++){
for(re int j = 1;j <= n;j ++){
dp[i][j] = dp[j][i] = min(dp[i][j],dp[i][k] + dp[j][k]);
}
}
k ++;
}
if(dp[x][y] == 99999999){
cout<<-1<<"\n";
}
else{
cout<<dp[x][y]<<"\n";
}
}
return 0;
}