已经特殊判断了是否需要最短路 但是还是TLE40分
#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
int n,m,q,t[maxn],l[maxn][maxn];
int main(){
cin>>n>>m;
for(int i = 0;i<n;i++){
cin>>t[i];
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
l[i][j] = 1e9;
}
}
for(int i = 0;i<n;i++)l[i][i] = 0;
for(int i = 1,x,y,z;i<=m;i++){
cin>>x>>y>>z;
l[x][y] = l[y][x] = z;
}
cin>>q;
for(int i = 1,x,y,ti,cnt;i<=q;i++){
cin>>x>>y>>ti;
if(t[x]>ti||t[y]>ti){
cout<<-1<<endl;
}else{
cnt = 0;
while(cnt<n&&t[cnt]<=ti){
for(int x = 0;x<n;x++){
for(int y = 0;y<n;y++){
l[y][x] = l[x][y] = min(l[x][y],l[x][cnt]+l[cnt][y]);
}
}
cnt++;
}
if(l[x][y]==1e9)cout<<-1<<endl;
else{
cout<<l[x][y]<<endl;
}
}
}
return 0;
}