結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-11-14 01:27:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,676 bytes |
| コンパイル時間 | 1,608 ms |
| コンパイル使用メモリ | 173,172 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:27:24 |
| 合計ジャッジ時間 | 2,674 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
struct Vertex {
int index, cost, time;
};
using State = Vertex;
class Solver {
public:
bool solve() {
int N, C, V; cin >> N >> C >> V;
vector<int> S(V), T(V), Y(V), M(V);
cin >> S >> T >> Y >> M;
vector<vector<Vertex>> E(N);
rep(i, V) {
S[i]--; T[i]--;
E[S[i]].push_back(Vertex{T[i], Y[i], M[i]});
// E[T[i]].push_back(Vertex{S[i], Y[i], M[i]});
}
auto comp = [=](const State &a, const State &b) {
return a.time > b.time;
};
priority_queue<State, vector<State>, decltype(comp)> que(comp);
que.push(State{0, 0, 0});
vector<set<int>> visited(N);
int ans = -1;
while(que.size()) {
State now = que.top(); que.pop();
if(now.index == N - 1) {
ans = now.time;
break;
}
if(visited[now.index].count(now.cost)) continue;
visited[now.index].insert(now.cost);
for(Vertex &nxt : E[now.index]) {
int c = now.cost + nxt.cost;
if(not visited[nxt.index].count(c) and c <= C) {
que.push(State{
nxt.index, c, now.time + nxt.time });
}
}
}
cout << ans << endl;
return 0;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Solver s;
s.solve();
return 0;
}
cormoran