結果

問題 No.1 道のショートカット
ユーザー nenuon
提出日時 2017-08-01 00:55:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,287 ms / 5,000 ms
コード長 1,371 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 95,112 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 16:32:46
合計ジャッジ時間 13,737 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int inf = 1e9;
int N,C,V;
int S[2000],T[2000],Y[2000],M[2000];
struct edge {
  int to, cost, times;
  edge(int a, int b, int c) {
    to = a, cost = b, times = c;
  }
};
vector<vector<edge> > G;
int dp[60][301];

void dfs(int v, int par) {
  for(edge &e : G[v]) {
    if(e.to == par) continue;
    bool next = false;
    FOR(i,0,301) {
      if(dp[v][i] == inf) continue;
      if(dp[e.to][i + e.cost] > dp[v][i] + e.times && i + e.cost <= 300) {
        next = true;
        dp[e.to][i + e.cost] = dp[v][i] + e.times;
      }
    }
    if(next) dfs(e.to, v);
  }
  return;
}
int main()
{
  cin >> N >> C >> V;
  G.resize(N+1);
  FOR(i,0,V) cin >> S[i];
  FOR(i,0,V) cin >> T[i];
  FOR(i,0,V) cin >> Y[i];
  FOR(i,0,V) cin >> M[i];
  G[0].push_back(edge(1,0,0));
  FOR(i,0,V) {
    G[S[i]].push_back(edge(T[i],Y[i],M[i]));
  }
  FOR(i,0,60) FOR(j,0,301) dp[i][j] = inf;
  dp[0][0] = 0;
  dfs(0, -1);
  int mn = inf;
  FOR(i,1,C+1) {
    mn = min(mn, dp[N][i]);
  }
  cout << (mn == inf ? -1 : mn) << endl;
  return 0;
}
0