Submission #533338

# Submission time Handle Problem Language Result Execution time Memory
533338 2022-03-05T14:03:56 Z ddy888 Autobus (COCI22_autobus) C++17
70 / 70
165 ms 9808 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 i = 1; i <= M; ++i) {
        int u, v, c; cin >> u >> v >> c;
        dist[u][v] = min(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) {
                dp[i][j][k] = INF;
                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 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3532 KB Output is correct
2 Correct 3 ms 3532 KB Output is correct
3 Correct 5 ms 3528 KB Output is correct
4 Correct 4 ms 3532 KB Output is correct
5 Correct 5 ms 3604 KB Output is correct
6 Correct 5 ms 3600 KB Output is correct
7 Correct 6 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 24 ms 3600 KB Output is correct
8 Correct 49 ms 3592 KB Output is correct
9 Correct 6 ms 3604 KB Output is correct
10 Correct 38 ms 3528 KB Output is correct
11 Correct 11 ms 3532 KB Output is correct
12 Correct 45 ms 3588 KB Output is correct
13 Correct 97 ms 4208 KB Output is correct
14 Correct 91 ms 4492 KB Output is correct
15 Correct 141 ms 4788 KB Output is correct
16 Correct 130 ms 9216 KB Output is correct
17 Correct 101 ms 5200 KB Output is correct
18 Correct 94 ms 7416 KB Output is correct
19 Correct 165 ms 7108 KB Output is correct
20 Correct 132 ms 8588 KB Output is correct
21 Correct 92 ms 7492 KB Output is correct
22 Correct 107 ms 8888 KB Output is correct
23 Correct 107 ms 8924 KB Output is correct
24 Correct 129 ms 7700 KB Output is correct
25 Correct 91 ms 7492 KB Output is correct
26 Correct 103 ms 6680 KB Output is correct
27 Correct 110 ms 3516 KB Output is correct
28 Correct 107 ms 3588 KB Output is correct
29 Correct 86 ms 3520 KB Output is correct
30 Correct 100 ms 7876 KB Output is correct
31 Correct 123 ms 9496 KB Output is correct
32 Correct 161 ms 9024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 2 ms 3532 KB Output is correct
8 Correct 3 ms 3532 KB Output is correct
9 Correct 5 ms 3528 KB Output is correct
10 Correct 4 ms 3532 KB Output is correct
11 Correct 5 ms 3604 KB Output is correct
12 Correct 5 ms 3600 KB Output is correct
13 Correct 6 ms 3584 KB Output is correct
14 Correct 24 ms 3600 KB Output is correct
15 Correct 49 ms 3592 KB Output is correct
16 Correct 6 ms 3604 KB Output is correct
17 Correct 38 ms 3528 KB Output is correct
18 Correct 11 ms 3532 KB Output is correct
19 Correct 45 ms 3588 KB Output is correct
20 Correct 97 ms 4208 KB Output is correct
21 Correct 91 ms 4492 KB Output is correct
22 Correct 141 ms 4788 KB Output is correct
23 Correct 130 ms 9216 KB Output is correct
24 Correct 101 ms 5200 KB Output is correct
25 Correct 94 ms 7416 KB Output is correct
26 Correct 165 ms 7108 KB Output is correct
27 Correct 132 ms 8588 KB Output is correct
28 Correct 92 ms 7492 KB Output is correct
29 Correct 107 ms 8888 KB Output is correct
30 Correct 107 ms 8924 KB Output is correct
31 Correct 129 ms 7700 KB Output is correct
32 Correct 91 ms 7492 KB Output is correct
33 Correct 103 ms 6680 KB Output is correct
34 Correct 110 ms 3516 KB Output is correct
35 Correct 107 ms 3588 KB Output is correct
36 Correct 86 ms 3520 KB Output is correct
37 Correct 100 ms 7876 KB Output is correct
38 Correct 123 ms 9496 KB Output is correct
39 Correct 161 ms 9024 KB Output is correct
40 Correct 14 ms 3532 KB Output is correct
41 Correct 50 ms 3584 KB Output is correct
42 Correct 9 ms 3532 KB Output is correct
43 Correct 75 ms 3588 KB Output is correct
44 Correct 13 ms 3660 KB Output is correct
45 Correct 73 ms 3596 KB Output is correct
46 Correct 89 ms 4368 KB Output is correct
47 Correct 123 ms 6968 KB Output is correct
48 Correct 99 ms 6120 KB Output is correct
49 Correct 153 ms 8904 KB Output is correct
50 Correct 91 ms 7620 KB Output is correct
51 Correct 114 ms 8016 KB Output is correct
52 Correct 89 ms 8892 KB Output is correct
53 Correct 159 ms 8784 KB Output is correct
54 Correct 95 ms 7376 KB Output is correct
55 Correct 94 ms 6788 KB Output is correct
56 Correct 152 ms 9400 KB Output is correct
57 Correct 154 ms 6288 KB Output is correct
58 Correct 94 ms 9764 KB Output is correct
59 Correct 117 ms 9616 KB Output is correct
60 Correct 149 ms 9808 KB Output is correct
61 Correct 162 ms 9732 KB Output is correct
62 Correct 95 ms 9540 KB Output is correct
63 Correct 104 ms 9536 KB Output is correct
64 Correct 105 ms 4348 KB Output is correct
65 Correct 154 ms 7348 KB Output is correct