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

FaQ

时间:2020-05-12 20:16:46      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:const   eof   div   blocks   nbsp   set   wro   using   pre   

// Hey buddy you get the wrong door, the leather club is two blocks down.

#include <bits/stdc++.h>

using namespace std;
const int N = 200, INF = 0x3f3f3f3f;

int t[N + 5], dis[N + 5][N + 5];
int n, m;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
    memset(dis, 63, sizeof(dis));
    for (int i = 1, u, v, w; i <= m; i++) 
        scanf("%d%d%d", &u, &v, &w), u++, v++, dis[u][v] = w, dis[v][u] = w;
    for (int i = 1; i <= n; i++) dis[i][i] = 0;
    int q, k = 1; 
    for (scanf("%d", &q); q--;)
    {
        int u, v, o;
        scanf("%d%d%d", &u, &v, &o), u++, v++;
        for (; t[k] <= o && k <= n; k++)
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        printf("%d\n", dis[u][v] == INF || t[u] > o || t[v] > o ? -1 : dis[u][v]);
    }
    return 0;
}

 

FaQ

标签:const   eof   div   blocks   nbsp   set   wro   using   pre   

原文地址:https://www.cnblogs.com/oply/p/12878125.html

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