結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-18 02:49:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,271 bytes |
| コンパイル時間 | 2,247 ms |
| コンパイル使用メモリ | 218,964 KB |
| 実行使用メモリ | 19,712 KB |
| 最終ジャッジ日時 | 2025-11-18 02:49:28 |
| 合計ジャッジ時間 | 4,745 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 36 WA * 4 |
ソースコード
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
//const int iris = 1e9+7;
const int iris = 998244353;
using namespace std;
using akari = pair<int,matsuri>;
void solve()
{
int n,C,V;
cin>>n>>C>>V;
vector<vector<vector<tuple<int,int,int> > > > G(n+1, vector<vector<tuple<int,int,int> > >(C+1));
vector<int> S(V), T(V), Y(V), M(V);
for(int &x:S)
cin>>x;
for(int &x:T)
cin>>x;
for(int &x:Y)
cin>>x;
for(int &x:M)
cin>>x;
vector<vector<int> > dis(n+1, vector<int>(C+1, 1e18));
for(int i=0;i<V;i++)
{
int a=S[i], b=T[i], c=Y[i], d=M[i];
for(int j=0;j+c<=C;j++)
{
G[a][j].emplace_back(b, j+c, d);
G[b][j].emplace_back(a, j+c, d);
}
}
dis[1][0]=0;
priority_queue<akari, vector<akari>, greater<akari> > pq;
pq.emplace(0, matsuri{1,0});
while(!pq.empty())
{
auto [d,_]=pq.top();
pq.pop();
auto [a,x]=_;
if(dis[a][x]!=d)
continue;
for(auto [b,y,c]:G[a][x])
{
if(dis[a][x]+c<dis[b][y])
{
dis[b][y]=dis[a][x]+c;
pq.emplace(dis[b][y], matsuri{b,y});
}
}
}
int ans=1e18;
for(int i=0;i<=C;i++)
ans=min(ans, dis[n][i]);
if(ans==1e18)
ans=-1;
cout<<ans<<'\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T=1;
//cin>>T;
while(T--)
solve();
return 0;
}