Submission #1056085

# Submission time Handle Problem Language Result Execution time Memory
1056085 2024-08-13T07:43:03 Z manhlinh1501 Autobus (COCI22_autobus) C++17
70 / 70
126 ms 8284 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int MAXN = 75;
const int oo32 = 1e9;

int N, M, K, Q;
int dp[MAXN][MAXN][MAXN];
int w[MAXN][MAXN];

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            w[i][j] = oo32;
        }
    }

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            for(int z = 0; z <= N; z++)
                dp[i][j][z] = oo32;
        }
    }

    for(int i = 1; i <= M; i++) {
        int u, v, x;
        cin >> u >> v >> x;
        dp[u][v][1] = min(dp[u][v][1], x);
        w[u][v] = min(w[u][v], x);
    }

    cin >> K >> Q;
    K = min(K, N - 1);
    for(int i = 1; i <= N; i++) dp[i][i][0] = 0;
    for(int x = 2; x <= K; x++) {
        for(int z = 1; z <= N; z++) {
            for(int u = 1; u <= N; u++) {
                for(int v = 1; v <= N; v++)
                    dp[u][v][x] = min(dp[u][v][x], dp[u][z][x - 1] + w[z][v]);
            }
        }
    }

    while(Q--) {
        int u, v;
        cin >> u >> v;
        int ans = oo32;
        for(int i = 0; i <= K; i++)
            ans = min(ans, dp[u][v][i]);
        cout << (ans == oo32 ? -1 : ans) << "\n";
    }
    return (0 ^ 0);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1884 KB Output is correct
2 Correct 2 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1884 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 2112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 10 ms 1884 KB Output is correct
8 Correct 27 ms 2140 KB Output is correct
9 Correct 2 ms 2016 KB Output is correct
10 Correct 12 ms 2064 KB Output is correct
11 Correct 5 ms 1884 KB Output is correct
12 Correct 16 ms 1888 KB Output is correct
13 Correct 58 ms 8016 KB Output is correct
14 Correct 60 ms 8140 KB Output is correct
15 Correct 72 ms 8016 KB Output is correct
16 Correct 72 ms 8272 KB Output is correct
17 Correct 74 ms 8016 KB Output is correct
18 Correct 64 ms 8020 KB Output is correct
19 Correct 76 ms 8016 KB Output is correct
20 Correct 70 ms 8020 KB Output is correct
21 Correct 94 ms 8272 KB Output is correct
22 Correct 60 ms 8144 KB Output is correct
23 Correct 60 ms 8272 KB Output is correct
24 Correct 71 ms 8272 KB Output is correct
25 Correct 88 ms 8280 KB Output is correct
26 Correct 63 ms 8268 KB Output is correct
27 Correct 74 ms 8272 KB Output is correct
28 Correct 75 ms 8272 KB Output is correct
29 Correct 60 ms 8020 KB Output is correct
30 Correct 60 ms 7912 KB Output is correct
31 Correct 121 ms 7876 KB Output is correct
32 Correct 77 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 1884 KB Output is correct
8 Correct 2 ms 1884 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1884 KB Output is correct
11 Correct 2 ms 1884 KB Output is correct
12 Correct 2 ms 1884 KB Output is correct
13 Correct 2 ms 2112 KB Output is correct
14 Correct 10 ms 1884 KB Output is correct
15 Correct 27 ms 2140 KB Output is correct
16 Correct 2 ms 2016 KB Output is correct
17 Correct 12 ms 2064 KB Output is correct
18 Correct 5 ms 1884 KB Output is correct
19 Correct 16 ms 1888 KB Output is correct
20 Correct 58 ms 8016 KB Output is correct
21 Correct 60 ms 8140 KB Output is correct
22 Correct 72 ms 8016 KB Output is correct
23 Correct 72 ms 8272 KB Output is correct
24 Correct 74 ms 8016 KB Output is correct
25 Correct 64 ms 8020 KB Output is correct
26 Correct 76 ms 8016 KB Output is correct
27 Correct 70 ms 8020 KB Output is correct
28 Correct 94 ms 8272 KB Output is correct
29 Correct 60 ms 8144 KB Output is correct
30 Correct 60 ms 8272 KB Output is correct
31 Correct 71 ms 8272 KB Output is correct
32 Correct 88 ms 8280 KB Output is correct
33 Correct 63 ms 8268 KB Output is correct
34 Correct 74 ms 8272 KB Output is correct
35 Correct 75 ms 8272 KB Output is correct
36 Correct 60 ms 8020 KB Output is correct
37 Correct 60 ms 7912 KB Output is correct
38 Correct 121 ms 7876 KB Output is correct
39 Correct 77 ms 8028 KB Output is correct
40 Correct 7 ms 1884 KB Output is correct
41 Correct 22 ms 2048 KB Output is correct
42 Correct 4 ms 1884 KB Output is correct
43 Correct 23 ms 2068 KB Output is correct
44 Correct 9 ms 1880 KB Output is correct
45 Correct 24 ms 2108 KB Output is correct
46 Correct 60 ms 8016 KB Output is correct
47 Correct 67 ms 8016 KB Output is correct
48 Correct 62 ms 8012 KB Output is correct
49 Correct 80 ms 8140 KB Output is correct
50 Correct 72 ms 8016 KB Output is correct
51 Correct 73 ms 8016 KB Output is correct
52 Correct 67 ms 8140 KB Output is correct
53 Correct 95 ms 8148 KB Output is correct
54 Correct 63 ms 8140 KB Output is correct
55 Correct 69 ms 8140 KB Output is correct
56 Correct 85 ms 8144 KB Output is correct
57 Correct 79 ms 8256 KB Output is correct
58 Correct 71 ms 8268 KB Output is correct
59 Correct 126 ms 8272 KB Output is correct
60 Correct 75 ms 8276 KB Output is correct
61 Correct 91 ms 8284 KB Output is correct
62 Correct 67 ms 7888 KB Output is correct
63 Correct 85 ms 8096 KB Output is correct
64 Correct 74 ms 8016 KB Output is correct
65 Correct 117 ms 8100 KB Output is correct