結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-09 23:41:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,857 bytes |
| コンパイル時間 | 1,781 ms |
| コンパイル使用メモリ | 178,200 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:27:03 |
| 合計ジャッジ時間 | 2,656 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct Node {
int at;
int time;
int cost;
Node(int at, int time, int cost) : at(at), time(time), cost(cost) {}
bool operator>(const Node &s) const {
if (time != s.time) return time > s.time;
if (cost != s.cost) return cost > s.cost;
return at > s.at;
}
};
struct Edge {
int to;
int time;
int cost;
Edge(int to, int time, int cost) : to(to), time(time), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList; //隣接リスト
typedef vector<Edge>::iterator Edge_it;
const int INF = 100000000;
const int NONE = -1;
AdjList graph;
int c;
void dijkstra(int s, int t, vector<int> &mint){
priority_queue<Node, vector<Node>, greater<Node> > pq;
pq.push(Node(s, 0, 0));
while(!pq.empty()) {
Node x = pq.top();
pq.pop();
if (x.cost > c) continue;
mint[x.at] = min(mint[x.at], x.time);
if (x.at == t) break;
for(Edge_it i = graph[x.at].begin(), e = graph[x.at].end(); i != e; ++i) {
int tmp_t = x.time + i->time;
int tmp_c = x.cost + i->cost;
if (tmp_c <= c) {
pq.push(Node(i->to, tmp_t, tmp_c));
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
int v;
cin >> n >> c >> v;
vector<int> s(v), t(v), y(v), m(v);
for (int i = 0; i < v; i++) cin >> s[i];
for (int i = 0; i < v; i++) cin >> t[i];
for (int i = 0; i < v; i++) cin >> y[i];
for (int i = 0; i < v; i++) cin >> m[i];
graph = AdjList(n);
for (int i = 0; i < v; i++) {
s[i]--;
t[i]--;
graph[s[i]].emplace_back(t[i], m[i], y[i]);
}
vector<int> mint(n, INF);
dijkstra(0, n - 1, mint);
cout << (mint[n - 1] == INF ? -1 : mint[n - 1]) << endl;
return 0;
}