結果

問題 No.1 道のショートカット
ユーザー どららどらら
提出日時 2015-05-30 12:44:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 80,596 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-22 12:16:14
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
4,380 KB
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 <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define INF 1000000000

int Y[55][55];
int M[55][55];

struct ST {
  int pos;
  int cost;
  int sec;
};

int solve(int N, int C){
  ST st;
  st.pos = 1;
  st.cost = 0;
  st.sec = 0;
  vector<int> visited(N+1, INF);

  queue<ST> que; que.push(st);
  while(!que.empty()){
    st = que.front(); que.pop();
    if(visited[st.pos] < st.sec) continue;
    visited[st.pos] = st.sec;
    
    REP(i,1,N+1){
      if(Y[st.pos][i] != INF){
        ST nxt;
        nxt.pos = i;
        nxt.cost = st.cost + Y[st.pos][i];
        nxt.sec = st.sec + M[st.pos][i];
        if(nxt.cost > C) continue;
        que.push(nxt);
      }
    }    
  }
  if(visited[N] == INF) return -1;
  return visited[N];
}

int main(){
  int N, C, V, tmp;

  rep(i,55) rep(j,55){
    Y[i][j] = INF;
    M[i][j] = INF;
  }
  
  cin >> N >> C >> V;
  vector<int> S, T;
  rep(i,V){
    cin >> tmp;
    S.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    T.push_back(tmp);
  }
  rep(i,V){
    cin >> tmp;
    Y[S[i]][T[i]] = tmp;
  }
  rep(i,V){
    cin >> tmp;
    M[S[i]][T[i]] = tmp;
  }
  
  cout << solve(N, C) << endl;

  return 0;
}
0