結果

問題 No.2739 Time is money
ユーザー ponjuiceponjuice
提出日時 2024-04-17 11:40:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 205,632 KB
実行使用メモリ 20,604 KB
最終ジャッジ日時 2024-04-17 11:40:47
合計ジャッジ時間 8,969 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 172 ms
13,568 KB
testcase_03 AC 320 ms
17,540 KB
testcase_04 AC 168 ms
13,144 KB
testcase_05 AC 233 ms
13,204 KB
testcase_06 AC 275 ms
15,940 KB
testcase_07 AC 381 ms
19,960 KB
testcase_08 AC 365 ms
20,176 KB
testcase_09 AC 396 ms
20,352 KB
testcase_10 AC 334 ms
19,584 KB
testcase_11 AC 366 ms
20,284 KB
testcase_12 AC 318 ms
18,688 KB
testcase_13 AC 337 ms
18,816 KB
testcase_14 AC 273 ms
18,804 KB
testcase_15 AC 240 ms
17,908 KB
testcase_16 AC 241 ms
16,916 KB
testcase_17 AC 376 ms
20,604 KB
testcase_18 AC 383 ms
20,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e18;

int main(){
    ll n, m, x;
    cin >> n >> m >> x;
    vector<vector<pair<int, ll>>> graph(n);
    for (int i = 0; i < m; i++) {
        ll u, v, c, t;
        cin >> u >> v >> c >> t;
        u--, v--;
        graph[u].emplace_back(v, t * x + c);
        graph[v].emplace_back(u, t * x + c);
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    vector<ll> cst(n, INF);
    q.push({0, 0});
    cst[0] = 0;

    while (!q.empty()) {
        auto [c, p] = q.top();
        q.pop();
        if (cst[p] != c) continue;

        for(auto [to, cp] : graph[p]){
            if(cst[p] + cp < cst[to]){
                cst[to] = cst[p] + cp;
                q.push({cst[to], to});
            }
        }
    }

    if(cst[n - 1] == INF){
        cout << -1 << endl;
    }else{
        cout << (cst[n-1] + x - 1) / x << endl;
    }
}
0