Submission #533337

# Submission time Handle Problem Language Result Execution time Memory
533337 2022-03-05T14:00:58 Z ddy888 Autobus (COCI22_autobus) C++17
0 / 70
3 ms 3532 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long 
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)

const int INF = 1e18;
int N, M, K, Q, dist[80][80], dp[80][80][80];

void chmin(int& x, int y) {
    x = min(x, y);
}

signed main() {
    fast;
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) {
        dist[i][j] = (i == j ? 0 : INF);
        for (int k = 1; k <= N; ++k) dp[i][j][k] = (i == j ? 0 : INF);
    }
    for (int i = 1; i <= M; ++i) {
        int u, v, c; cin >> u >> v >> c;
        dist[u][v] = c;
    }
    cin >> K >> Q;
    for (int k = 1; k <= min(N, K); ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                if (k == 1) {
                    if (dist[i][j] != INF) chmin(dp[i][j][k], dist[i][j]);
                } else {
                    for (int mid = 1; mid <= N; ++mid) {
                        if (dist[mid][j] != INF) chmin(dp[i][j][k], dp[i][mid][k - 1] + dist[mid][j]);
                    }
                }
            }
        }
    }
    while (Q--) {
        int u, v; cin >> u >> v;
        int ans = INF;
        for (int i = 1; i <= min(N, K); ++i) chmin(ans, dp[u][v][i]);
        cout << (ans == INF ? -1 : ans) << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -