样例过了,提交大紫大红
查看原帖
样例过了,提交大紫大红
1013950
__youzimo2014__楼主2024/9/26 20:33

tips

#include <iostream>
#include <vector>
#define _LONG_MAX_ 10000000000ULL
#define int unsigned long long
using namespace std;
int t[200];
vector<int> G[200], val[200];
int e[200][200], d;
int n, m;
void update(int kd) {
    for (int k = d+1; k <= kd; k++) {
        e[k][k] = 0;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                if (e[i][j] > e[i][k] + e[j][k]) {
                    e[i][j] = e[j][i] = e[i][k] + e[j][k];
                }
            }
        }
    }
    d = kd;
}
signed main(signed argc, const char * argv[]) {
    // insert code here...
    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++) {
            e[i][j] = _LONG_MAX_;
        }
    }
    for (int i = 0; i < m; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        G[x].push_back(y); e[x][y] = w;
        G[y].push_back(x); e[y][x] = w;
        val[x].push_back(w);
        val[y].push_back(w);
    }
    int q;
    cin >> q;
    while (q--) {
        int x, y, T;
        cin >> x >> y >> T;
        if (t[x] > T || t[y] > T) {
            cout << -1 << endl;
            continue;
        }
        int kd = d;
        for (;kd < n; kd++) {
            if (t[kd] > T) {
                break;
            }
        }
        kd--;
        update(kd);
        if (e[x][y] == _LONG_MAX_) {
            cout << -1 << endl;
            continue;
        }
        cout << e[x][y] << endl;
    }
    return 0;
}

2024/9/26 20:33
加载中...