結果

問題 No.1 道のショートカット
ユーザー d2verbd2verb
提出日時 2015-05-05 00:06:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,385 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 84,696 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 12:09:13
合計ジャッジ時間 2,628 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 RE -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int N, C, V, data[4][50];
int ans = INF;

struct edge{
    int to, cost, time;
    edge(int to, int cost, int time){
        this->to = to;
        this->cost = cost;
        this->time = time;
    }
};

vector<edge> G[51];

void solve(int n, int t, int c){
    if(n == N){
        if(c <= C) ans = min(ans, t);
        return;
    }
    if(c > C) return;
    
    for(int i = 0; i < G[n].size(); i++){
        solve(G[n][i].to, t + G[n][i].time, c + G[n][i].cost);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin >> N >> C >> V;
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < V; j++) cin >> data[i][j];
    }

    for(int i = 0; i < V; i++){
        int s = data[0][i], t = data[1][i];
        int y = data[2][i], m = data[3][i];
        G[s].push_back(edge(t, y, m));
    }

    solve(1, 0, 0);
    
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0