답안 #1106124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106124 2024-10-29T10:15:33 Z atom Autobus (COCI22_autobus) C++17
0 / 70
3 ms 592 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 ll INF = 1e18; 
ll d[N][N];
int cnt[N][N];

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

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

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            d[i][j] = INF;
            if (i == j) d[i][j] = 0;
        }
    }

    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 = 0; i < m; ++i) {
        auto [u, v, w] = edges[i];
        if (w < d[u][v]) {
            d[u][v] = w;
            cnt[u][v] = 1;
        }
    }

    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (d[i][k] + d[k][j] < d[i][j] && cnt[i][k] + cnt[k][j] <= K) {
                    d[i][j] = d[i][k] + d[k][j];
                    cnt[i][j] = cnt[i][k] + cnt[k][j];
                }
                else if (d[i][k] + d[k][j] == d[i][j] && cnt[i][k] + cnt[k][j] <= K) {
                    cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j]);
                }
            }
        }
    }

    // cout << d[1][4] << "\n";

   
    for (int _q = 1; _q <= q; ++_q) {
        int x, y;
        cin >> x >> y;
        if (d[x][y] == INF || cnt[x][y] > K) {
            cout << "-1\n";
        }
        else 
            cout << d[x][y] << "\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 Incorrect 1 ms 472 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 476 KB Output is correct
2 Incorrect 2 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 472 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 1 ms 472 KB Output isn't correct
6 Halted 0 ms 0 KB -