結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
_shim0123_
|
| 提出日時 | 2015-05-05 12:08:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,471 bytes |
| コンパイル時間 | 688 ms |
| コンパイル使用メモリ | 76,064 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-08 03:55:59 |
| 合計ジャッジ時間 | 1,951 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 WA * 8 |
ソースコード
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
#define INF 10000000
typedef pair < unsigned, unsigned > P;
class edge{
public:
unsigned to;
unsigned cost;
unsigned time;
edge(unsigned a, unsigned b, unsigned c) {
to = a;
cost = b;
time = c;
}
};
int main(void) {
unsigned N = 0, C = 0, V = 0;
unsigned S[1500] = {0}, T[1500] = {0}, Y[1500] = {0}, M[1500] = {0};
vector<edge> G[51];
priority_queue<P ,vector<P>, greater<P>> que;
unsigned time[51], money[51] = {0};
cin >> N >> C >> V;
for(unsigned i = 0; i < V; i++){
cin >> S[i];
}
for(unsigned i = 0; i < V; i++){
cin >> T[i];
}
for(unsigned i = 0; i < V; i++){
cin >> Y[i];
}
for(unsigned i = 0; i < V; i++){
cin >> M[i];
}
for(unsigned i = 0; i < V; i++){
edge e(T[i], Y[i], M[i]);
G[S[i]].push_back(e);
}
for(unsigned i = 1; i <= N; i++){
time[i] = INF;
}
que.push(P(1,0));
time[1] = 0;
money[1] = 0;
while(!que.empty()){
P p = que.top();
que.pop();
unsigned pos = p.first, t = p.second;
if(time[pos] < t){
continue;
}
for(unsigned i = 1; i <= N; i++){
for(auto e : G[pos]){
if(time[e.to] > time[pos] + e.time && C>=money[pos]+e.cost){
money[e.to] = money[pos] + e.cost;
time[e.to] = time[pos] + e.time;
que.push(P(e.to,time[e.to]));
}
}
}
}
if(time[N] != INF){
cout << time[N] << endl;
}
else{
cout << -1 << endl;
}
return 0;
}
_shim0123_