Submission #703973

# Submission time Handle Problem Language Result Execution time Memory
703973 2023-03-01T07:28:37 Z ancuber1031 Autobus (COCI22_autobus) C++14
0 / 70
2 ms 340 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define p_q priority_queue
#define endl '\n'
#define pb push_back

int n, m;

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n>>m;
    vector<vector<int> > dp(n+1,vector<int>(n+1,1e18)), cnt(n+1,vector<int>(n+1,0));
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;
    while(m--) {
        int a, b, t;
        cin>>a>>b>>t;
        dp[a][b] = min(t,dp[a][b]);
        cnt[a][b] = 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) {
                if (cnt[i][l]+cnt[l][j] > k) continue;
                if (dp[i][j] >= dp[i][l]+dp[l][j]) {
                    dp[i][j] = dp[i][l]+dp[l][j];
                    cnt[i][j] = cnt[i][l]+cnt[l][j];
                }
            }
        }
    }
    while(q--) {
        int c, d; cin>>c>>d;
        if (dp[c][d] >= 1e18) cout<<-1<<endl;
        else cout<<dp[c][d]<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -