답안 #1056075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056075 2024-08-13T07:38:23 Z manhlinh1501 Autobus (COCI22_autobus) C++17
0 / 70
2 ms 2184 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);

    memset(dp, 0x3f, sizeof dp);
    memset(w, 0x3f, sizeof w);

    cin >> N >> M;

    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 z = 1; z <= N; z++) {
        for(int u = 1; u <= N; u++) {
            for(int v = 1; v <= N; v++) {
                for(int x = 2; x <= K; x++)
                    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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Incorrect 1 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2144 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Incorrect 2 ms 2184 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Incorrect 1 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2136 KB Output is correct
2 Incorrect 1 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -