結果

問題 No.2739 Time is money
ユーザー t98slidert98slider
提出日時 2024-04-20 13:22:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 207,068 KB
実行使用メモリ 20,632 KB
最終ジャッジ日時 2024-04-20 13:22:08
合計ジャッジ時間 6,356 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 81 ms
13,440 KB
testcase_03 AC 189 ms
17,440 KB
testcase_04 AC 126 ms
13,056 KB
testcase_05 AC 108 ms
13,228 KB
testcase_06 AC 137 ms
15,824 KB
testcase_07 AC 206 ms
20,096 KB
testcase_08 AC 222 ms
20,128 KB
testcase_09 AC 199 ms
20,352 KB
testcase_10 AC 150 ms
19,828 KB
testcase_11 AC 193 ms
20,416 KB
testcase_12 AC 147 ms
18,816 KB
testcase_13 AC 143 ms
18,816 KB
testcase_14 AC 133 ms
18,728 KB
testcase_15 AC 106 ms
17,700 KB
testcase_16 AC 102 ms
16,948 KB
testcase_17 AC 177 ms
20,504 KB
testcase_18 AC 198 ms
20,632 KB
testcase_19 AC 121 ms
17,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v;
    ll x, c, t;
    cin >> n >> m >> x;
    vector<vector<pair<int,ll>>> g(n);
    for(int i = 0; i < m; i++){
        cin >> u >> v >> c >> t;
        u--, v--;
        g[u].emplace_back(v, c + t * x);
        g[v].emplace_back(u, c + t * x);
    }
    vector<ll> dp(n, 1ll << 62);
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
    pq.emplace(0, 0);
    dp[0] = 0;
    while(!pq.empty()){
        tie(t, v) = pq.top();
        pq.pop();
        if(t > dp[v]) continue;
        for(auto [u, w] : g[v]){
            if(t + w >= dp[u]) continue;
            dp[u] = t + w;
            pq.emplace(dp[u], u);
        }
    }
    cout << (dp.back() >> 62 ? -x : dp.back() + x - 1) / x << '\n';
}
0