結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-21 17:58:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,668 bytes |
| コンパイル時間 | 1,740 ms |
| コンパイル使用メモリ | 181,520 KB |
| 実行使用メモリ | 28,312 KB |
| 最終ジャッジ日時 | 2024-07-08 05:28:52 |
| 合計ジャッジ時間 | 3,616 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n = 55 * 305;
int m;
vector<vector<pll>> graph(n,vector<pll>());
vector<ll> Dijkstra(int start){
vector<bool> seen(55 * 305,false);
vector<ll> shortest(55 * 305,LINF);
priority_queue<pll,vector<pll>,greater<pll>> pq;
pq.push(pll(0,start));
while(!pq.empty()){
ll dist = pq.top().first;
int node = pq.top().second;
pq.pop();
if(seen[node]) continue;
shortest[node] = dist;
seen[node] = true;
for(pll next:graph[node]){
int next_node = next.second;
ll next_cost = next.first;
if(seen[next_node]) continue;
pq.push(pll(next_cost + dist,next_node));
}
}
return shortest;
}
int main(){
cin >> n;
int c;
cin >> c;
cin >> m;
vector<int> a(m),b(m),y(m),t(m);
rep(i,m) cin >> a[i],--a[i];
rep(i,m) cin >> b[i],--b[i];
rep(i,m) cin >> y[i];
rep(i,m) cin >> t[i];
rep(i,m){
for(int j=y[i];j<=300;j++){
graph[a[i]*301+j].push_back(pll(t[i],b[i]*301+j-y[i]));
graph[b[i]*301+j].push_back(pll(t[i],a[i]*301+j-y[i]));
}
}
vector<ll> answer = Dijkstra(0 + c);
ll ans = LINF;
rep(i,c+1){
ans = min(ans,answer[(n-1)*301+i]);
}
if(ans==LINF) cout << -1 << endl;
else cout << ans << endl;
return 0;
}