제출 #1331130

#제출 시각아이디문제언어결과실행 시간메모리
1331130Zone_zoneeAutobus (COCI22_autobus)C++20
0 / 70
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 75;

pair<int, int> dist[N][N];
pair<int, int> operator+(pair<int, int> a, pair<int, int> b){
    return {a.first+b.first, a.second+b.second};
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            if(i == j) dist[i][j] = {0, 0};
            else dist[i][j] = {1e9, 0};
        }
    }
    while(m--){
        int u, v, t;
        cin >> u >> v >> t;
        dist[u][v] = min(dist[u][v], {t, 1});
    }
    int k, q;
    cin >> k >> q;
    for(int l = 1; l <= n; ++l){
        for(int i = 1; i <= n; ++i){
            for(int j = 1; j <= n; ++j){
                pair<int, int> t = dist[i][l]+dist[l][j];
                if(t.second > k || t.first >= 1e9) continue;
                dist[i][j] = min(dist[i][j], t);
            }
        }
    }
    while(q--){
        int x, y;
        cin >> x >> y;
        if(dist[x][y].second > k || dist[x][y].first >= 1e9) cout << -1 << '\n';
        else cout << dist[x][y].first << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...