結果

問題 No.2739 Time is money
ユーザー ilovenaomiilovenaomi
提出日時 2024-04-21 06:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,310 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 209,100 KB
実行使用メモリ 89,212 KB
最終ジャッジ日時 2024-04-21 06:51:50
合計ジャッジ時間 20,420 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 484 ms
38,528 KB
testcase_03 WA -
testcase_04 AC 502 ms
37,420 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 957 ms
63,944 KB
testcase_11 WA -
testcase_12 AC 981 ms
89,160 KB
testcase_13 AC 1,002 ms
89,212 KB
testcase_14 AC 975 ms
89,208 KB
testcase_15 WA -
testcase_16 AC 513 ms
68,736 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 899 ms
59,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <=(int)(n); i++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
using namespace std;

map<pair<int,int>, ll> mpc,mpt;
ll ans = -1;
ll x;
void dfs(int goal,vector<vector<int>>& graph,vector<bool>&passed, 
            int start, ll cost, ll time){
    if( start == goal){
        ll atime = cost / x;
        if( cost % x != 0) atime++;

        if( ans == -1){
            ans = atime+time;
        }else{
            ans = min(ans,atime+time);
        }


        return ;
    }
    passed[start] = true;
    for( auto nx: graph[start]){
        if( passed[nx] == false){
            dfs(goal,graph,passed,nx, 
                cost+mpc[{start,nx}],
                time+mpt[{start,nx}]);
        }  
    }
}

int main() {
    int n,m;
    cin >> n >> m >> x;
    vector<vector<int>> graph(n);
    rep(i,m){
        int u,v;
        ll c,t;
        cin >> u >> v >> c >> t;
        v--;
        u--;
        mpt[{u,v}] = t;
        mpc[{u,v}] = c;
        mpt[{v,u}] = t;
        mpc[{v,u}] = c;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<bool> passed(n,false);
    ans = -1;
    dfs(n-1,graph,passed,0,0,0);

    cout << ans << endl;
}

0