标签:ons fun cxf printf scan include ber ios word
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 205;
const int big_num = 0x3f3f3f3f;
int t[maxn],dis[maxn][maxn],vis[maxn];
int main()
{
int i,j,k;
int m,n;
memset(dis,0x3f,sizeof(dis));
scanf("%d%d",&n,&m);
for(i = 1; i <= maxn; i++)
dis[i][i] = 0;
for(i = 1; i <= n; i++)
scanf("%d",&t[i]);
for(i = 1; i <= m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
u++; v++;
dis[u][v] = dis[v][u] = w;
}
int q;
scanf("%d",&q);
while(q--)
{
int x,y,day;
scanf("%d%d%d",&x,&y,&day);
x++; y++;
for(k = 1; k <= n; k++)
{
if(vis[k] || t[k] > day) continue;
vis[k] = 1;
for(i = 1; i <= n; i++)
for(j = 1; j <= n; j++)
dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
}
if(dis[x][y] == big_num || !vis[x] || !vis[y])
printf("-1\n");
else
printf("%d\n",dis[x][y]);
}
return 0;
}
fcxfxz
标签:ons fun cxf printf scan include ber ios word
原文地址:http://www.cnblogs.com/gzy20020702/p/7616792.html