結果

問題 No.2739 Time is money
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-20 10:25:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,252 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 213,272 KB
実行使用メモリ 25,464 KB
最終ジャッジ日時 2024-04-20 10:25:55
合計ジャッジ時間 7,311 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 78 ms
16,256 KB
testcase_03 AC 182 ms
22,108 KB
testcase_04 AC 70 ms
15,744 KB
testcase_05 AC 112 ms
16,476 KB
testcase_06 AC 148 ms
20,916 KB
testcase_07 AC 203 ms
24,592 KB
testcase_08 AC 243 ms
24,912 KB
testcase_09 AC 197 ms
25,252 KB
testcase_10 AC 160 ms
24,432 KB
testcase_11 AC 211 ms
25,308 KB
testcase_12 AC 149 ms
23,552 KB
testcase_13 AC 151 ms
23,552 KB
testcase_14 AC 137 ms
23,552 KB
testcase_15 WA -
testcase_16 AC 116 ms
21,504 KB
testcase_17 AC 208 ms
25,456 KB
testcase_18 AC 219 ms
25,464 KB
testcase_19 AC 165 ms
23,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    long long N,M,X; cin >> N >> M >> X;
    vector<vector<tuple<int,long long,long long>>> Graph(N);
    for(int i=0; i<M; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        long long c,t; cin >> c >> t;
        Graph.at(u).push_back({v,c%X,t+c/X});
        Graph.at(v).push_back({u,c%X,t+c/X});
    }

    long long inf = 1e18;
    vector<bool> already(N);
    vector<pair<long long,long long>> dist(N,{inf,inf});
    priority_queue<tuple<long long,long long,int>,vector<tuple<long long,long long,int>>,greater<>> Q;
    dist.at(0) = {0,0}; Q.push({0,0,0});
    while(Q.size()){
        auto[T,C,pos] = Q.top(); Q.pop();
        if(already.at(pos)) continue;
        already.at(pos) = true;

        for(auto [to,c,t] : Graph.at(pos)){
            if(already.at(to)) continue;
            if(C < c){if(dist.at(to) > make_pair(T+t+1,C+X-c)) dist.at(to) = {T+t+1,C+X-c},Q.push({T+t+1,C+X-c,to});}
            else if(dist.at(to) > make_pair(T+t,C-c)) dist.at(to) = {T+t,C-c},Q.push({T+t,C-c,to});
        }
    }
    if(dist.at(N-1).first == inf){cout << -1 << endl;}
    else cout << dist.at(N-1).first << endl;
}
0