码迷,mamicode.com
首页 > 其他好文 > 详细

fcxfxz

时间:2017-10-01 11:21:25      阅读:127      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!