結果

問題 No.1 道のショートカット
ユーザー chlo27chlo27
提出日時 2018-12-27 07:20:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,230 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 180,740 KB
実行使用メモリ 5,496 KB
最終ジャッジ日時 2023-09-22 13:27:23
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
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 RE -
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 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

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()+1;
  // 探索する頂点の情報 (最短距離, コスト, 頂点)を格納
  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(v+1);
  cout << graph.size() << endl << endl;
  // 次の点, コスト, 時間の隣接リスト
  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