結果

問題 No.1 道のショートカット
ユーザー chlo27chlo27
提出日時 2018-12-27 07:45:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 2,182 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 182,156 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:17:49
合計ジャッジ時間 3,463 ms
ジャッジサーバーID
(参考情報)
judge13 / 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,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,380 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 irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


vector<vector<int>> dijkstra(const vector<vector<tuple<int,int,int>>> &graph, const int start, const int max_cost){
  const int INF=1<<29;
  using ituple = tuple<int,int,int>;
  // グラフの頂点の数
  int v = graph.size();
  // 探索する頂点の情報 (最短距離, コスト, 頂点)を格納
  priority_queue<ituple, vector<ituple>, greater<ituple>> que;
  // 各点までのコスト毎の最短距離
  vector<vector<int>> min_d(v, vector<int>(max_cost+1 ,INF));

  min_d[start][0] = 0;
  que.push(ituple(0,0,start));

  while(!que.empty()){
    int dist_to_current, cost_to_current, current;
    tie(dist_to_current, cost_to_current, current) = que.top(); que.pop();
    if(min_d[current][cost_to_current] < dist_to_current) continue;
    for(int i=0; i < (int)graph[current].size(); ++i){
      int next, cost, dist;
      tie(next, cost, dist) = graph[current][i];
      if(cost_to_current+cost > max_cost) continue;
      if(min_d[next][cost_to_current+cost] > min_d[current][cost_to_current] + dist){
        min_d[next][cost_to_current+cost] = min_d[current][cost_to_current] + dist;
        que.push(ituple(min_d[next][cost_to_current+cost], cost_to_current+cost, next));
      }
    }
  }
  return min_d;
}

int main (void)
{
  int n,c,v; cin>>n>>c>>v;
  vector<int> s(1501),t(1501),y(1501),m(1501);
  rep1(i,v) cin>>s[i];
  rep1(i,v) cin>>t[i];
  rep1(i,v) cin>>y[i];
  rep1(i,v) cin>>m[i];
  using ituple = tuple<int,int,int>;
  vector<vector<ituple>> graph(n+1);
  // 次の点, コスト, 時間の隣接リスト
  rep1(i,v) graph[s[i]].push_back(ituple(t[i],y[i],m[i]));

  vector<vector<int>> dists = dijkstra(graph,1,c);
  int ans = *min_element(all(dists[n]));
  cout << (ans!=INF ? ans : -1) << endl;
  return 0;
}
0