답안 #1106132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106132 2024-10-29T10:33:02 Z atom Autobus (COCI22_autobus) C++17
70 / 70
123 ms 14656 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

const int N = 75;
const int INF = 1e9; 
int dp[N][N][N], d[N][N];

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in3", "r", stdin);
    #endif

    int n, m;
    cin >> n >> m;

    vector <array <int, 3>> edges;
    for (int i = 1; i <= m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        edges.push_back({u, v, w});
    }

    int K, q;
    cin >> K >> q;
    
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            d[i][j] = INF;
            if (i == j) continue;
            for (int k = 0; k <= n; ++k) {
                dp[i][j][k] = INF;
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        auto [u, v, w] = edges[i];
        dp[u][v][1] = min(dp[u][v][1], w);
        d[u][v] = min(d[u][v], w);
    }

    // cout << dp[1][2][1] << "\n";
    for (int k = 2; k <= min(n, K); ++k) {
        for (int z = 1; z <= n; ++z) {
            for (int x = 1; x <= n; ++x) {
                for (int y = 1; y <= n; ++y) {
                    dp[x][y][k] = min(dp[x][y][k], dp[x][z][k - 1] + d[z][y]);
                }
            }
        }
    } 

    for (int _q = 1; _q <= q; ++_q) {
        int x, y;
        cin >> x >> y;
        int ans = INF;
        for (int k = 1; k <= min(n, K); ++k)
            ans = min(ans, dp[x][y][k]);
        cout << (ans == INF? -1 : ans) << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1872 KB Output is correct
2 Correct 3 ms 1872 KB Output is correct
3 Correct 3 ms 1872 KB Output is correct
4 Correct 3 ms 2112 KB Output is correct
5 Correct 3 ms 2128 KB Output is correct
6 Correct 4 ms 2128 KB Output is correct
7 Correct 4 ms 2144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 11 ms 1872 KB Output is correct
8 Correct 28 ms 2060 KB Output is correct
9 Correct 5 ms 1872 KB Output is correct
10 Correct 16 ms 2128 KB Output is correct
11 Correct 7 ms 2128 KB Output is correct
12 Correct 20 ms 2128 KB Output is correct
13 Correct 70 ms 14316 KB Output is correct
14 Correct 71 ms 14272 KB Output is correct
15 Correct 92 ms 14256 KB Output is correct
16 Correct 76 ms 14256 KB Output is correct
17 Correct 81 ms 14600 KB Output is correct
18 Correct 71 ms 14504 KB Output is correct
19 Correct 95 ms 14528 KB Output is correct
20 Correct 89 ms 14408 KB Output is correct
21 Correct 70 ms 14508 KB Output is correct
22 Correct 76 ms 14368 KB Output is correct
23 Correct 80 ms 14592 KB Output is correct
24 Correct 87 ms 14504 KB Output is correct
25 Correct 81 ms 14640 KB Output is correct
26 Correct 85 ms 14492 KB Output is correct
27 Correct 90 ms 14656 KB Output is correct
28 Correct 96 ms 14420 KB Output is correct
29 Correct 80 ms 14256 KB Output is correct
30 Correct 89 ms 14268 KB Output is correct
31 Correct 90 ms 14256 KB Output is correct
32 Correct 99 ms 14260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 1872 KB Output is correct
8 Correct 3 ms 1872 KB Output is correct
9 Correct 3 ms 1872 KB Output is correct
10 Correct 3 ms 2112 KB Output is correct
11 Correct 3 ms 2128 KB Output is correct
12 Correct 4 ms 2128 KB Output is correct
13 Correct 4 ms 2144 KB Output is correct
14 Correct 11 ms 1872 KB Output is correct
15 Correct 28 ms 2060 KB Output is correct
16 Correct 5 ms 1872 KB Output is correct
17 Correct 16 ms 2128 KB Output is correct
18 Correct 7 ms 2128 KB Output is correct
19 Correct 20 ms 2128 KB Output is correct
20 Correct 70 ms 14316 KB Output is correct
21 Correct 71 ms 14272 KB Output is correct
22 Correct 92 ms 14256 KB Output is correct
23 Correct 76 ms 14256 KB Output is correct
24 Correct 81 ms 14600 KB Output is correct
25 Correct 71 ms 14504 KB Output is correct
26 Correct 95 ms 14528 KB Output is correct
27 Correct 89 ms 14408 KB Output is correct
28 Correct 70 ms 14508 KB Output is correct
29 Correct 76 ms 14368 KB Output is correct
30 Correct 80 ms 14592 KB Output is correct
31 Correct 87 ms 14504 KB Output is correct
32 Correct 81 ms 14640 KB Output is correct
33 Correct 85 ms 14492 KB Output is correct
34 Correct 90 ms 14656 KB Output is correct
35 Correct 96 ms 14420 KB Output is correct
36 Correct 80 ms 14256 KB Output is correct
37 Correct 89 ms 14268 KB Output is correct
38 Correct 90 ms 14256 KB Output is correct
39 Correct 99 ms 14260 KB Output is correct
40 Correct 9 ms 2040 KB Output is correct
41 Correct 28 ms 1872 KB Output is correct
42 Correct 6 ms 2040 KB Output is correct
43 Correct 34 ms 1872 KB Output is correct
44 Correct 7 ms 2128 KB Output is correct
45 Correct 33 ms 2276 KB Output is correct
46 Correct 80 ms 14252 KB Output is correct
47 Correct 91 ms 14256 KB Output is correct
48 Correct 83 ms 14260 KB Output is correct
49 Correct 123 ms 14260 KB Output is correct
50 Correct 85 ms 14512 KB Output is correct
51 Correct 78 ms 14380 KB Output is correct
52 Correct 82 ms 14516 KB Output is correct
53 Correct 103 ms 14448 KB Output is correct
54 Correct 88 ms 14508 KB Output is correct
55 Correct 82 ms 14508 KB Output is correct
56 Correct 101 ms 14392 KB Output is correct
57 Correct 101 ms 14508 KB Output is correct
58 Correct 83 ms 14580 KB Output is correct
59 Correct 86 ms 14512 KB Output is correct
60 Correct 101 ms 14512 KB Output is correct
61 Correct 123 ms 14548 KB Output is correct
62 Correct 76 ms 14256 KB Output is correct
63 Correct 84 ms 14252 KB Output is correct
64 Correct 80 ms 14260 KB Output is correct
65 Correct 109 ms 14256 KB Output is correct