zoukankan      html  css  js  c++  java
  • luogu_1119 灾后重建

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    const int N=210;
    const int M=N*N/2;
    const int INF=1<<20;
    int n,m,t[N],d[N][N],q,cnt;
    bool vis[N];
    
    int main(){
    	scanf("%d%d",&n,&m);
    	for(int i=0;i<n;i++)
    		for(int j=0;j<n;j++)d[i][j]=INF;
    	for(int i=0;i<n;i++)scanf("%d",&t[i]);
    	while(m--){
    		int u,v,w;
    		scanf("%d%d%d",&u,&v,&w);
    		d[u][v]=d[v][u]=w;
    	}
    	scanf("%d",&q);
    	while(q--){
    		int beg,end,nt;
    		scanf("%d%d%d",&beg,&end,&nt);
    		while(t[cnt]<=nt && cnt<n){
    			for(int i=0;i<n;i++)
    				for(int j=0;j<n;j++)d[i][j]=min(d[i][j],d[i][cnt]+d[cnt][j]);
    			cnt++;
    		}
    		if(t[beg]>nt || t[end]>nt || d[beg][end]==INF)puts("-1");
    		else printf("%d
    ",d[beg][end]);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    uva 10129
    年化利率
    house买房原理,2019,第一版
    car二手车购买原理
    car购车翻译篇
    car配置篇
    健身原理
    语法学习,从句
    语法学习,简单语句
    名词解释
  • 原文地址:https://www.cnblogs.com/codetogether/p/7582640.html
Copyright © 2011-2022 走看看