結果

問題 No.1 道のショートカット
ユーザー togatoga
提出日時 2015-04-10 20:40:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 2,018 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 92,240 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-07-08 03:50:56
合計ジャッジ時間 7,062 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N;
int C;
int V;
int S[55];
int T[55];
int Y[55];
int M[55];
int dp[55][330];
struct State{
  int tar;
  int mcost;
  int tcost;
  State(int _tar, int _mcost, int _tcost){
    tar = _tar;
    mcost = _mcost;
    tcost = _tcost;
  }
};
vector<State> graph[55];
int memo(int pos, int money){
  // cout << pos << " " << money << endl;
  if (pos == N){

    return 0;
  }
  if (dp[pos][money] < INF){
    return dp[pos][money];
  }
  int res = INF;
  for (int i = 0; i < graph[pos].size(); i++){
    State p = graph[pos][i];
    if (money - p.mcost >= 0){
      res = min(res, memo(p.tar, money - p.mcost) + p.tcost);
    }
  }
  // cout << "res = " << res << endl;
  return dp[pos][money] = res;
}
int main(){
  cin >> N;
  cin >> C;
  cin >> V;
  for (int i = 0; i < V; i++){
    cin >> S[i];
  }
  for (int i = 0; i < V; i++){
    cin >> T[i];
  }
  for (int i = 0; i < V; i++){
    cin >> Y[i];
  }

  for (int i = 0; i < V; i++){
    cin >> M[i];
  }

  for (int i = 0; i < V; i++){
    graph[S[i]].push_back(State(T[i], Y[i], M[i]));
    graph[T[i]].push_back(State(S[i], Y[i], M[i]));
  }

  for (int i = 0; i < 55; i++){
    for (int j = 0; j < 330; j++){
      dp[i][j] = INF;
    }
  }
  int res = memo(1, C);
  if (res != INF){
    cout << res << endl;
  }else{
    cout << - 1 << endl;
  }

  return 0;
}
0