結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2015-09-07 20:53:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,692 bytes |
コンパイル時間 | 673 ms |
コンパイル使用メモリ | 79,140 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-08 04:12:35 |
合計ジャッジ時間 | 1,814 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 WA * 7 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <sstream> #include <map> #include <set> #include <queue> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> P; int n,c,v; struct edge { int from,to; int cost,time; edge(int t,int c) : to(t),cost(c) {} edge(int f,int t,int c) : from(f),to(t),cost(c) {} edge(int f,int t,int c,int time) : from(f),to(t),cost(c),time(time) {} bool operator<(const edge &e) const { return cost < e.cost; } }; vector<edge> G[55]; int d[55],q[55]; void dijkstra(int s,int n) { priority_queue<P,vector<P>,greater<P> > que; fill(d,d+n,INF); memset(q,0,sizeof(q)); d[s] = 0; que.push(P(0,s)); while(que.size()) { P p = que.top(); que.pop(); int v = p.second; if(d[v] < p.first) continue; rep(i,G[v].size()) { edge e = G[v][i]; if(d[e.to] >= d[v] + e.cost && q[v] + e.time <= c) { d[e.to] = d[v] + e.cost; q[e.to] = q[v] + e.time; que.push(P(d[e.to],e.to)); } } } } int main() { cin >> n >> c >> v; vector<int> S(v),T(v),Y(v),M(v); rep(i,v) cin >> S[i]; rep(i,v) cin >> T[i]; rep(i,v) cin >> Y[i]; rep(i,v) cin >> M[i]; rep(i,v) { edge e(S[i]-1,T[i]-1,M[i],Y[i]); G[S[i]-1].push_back(e); } dijkstra(0,n); if(d[n-1] == INF) cout << -1 << endl; else cout << d[n-1] << endl; return 0; }