結果
問題 | No.3111 Toll Optimization |
ユーザー |
![]() |
提出日時 | 2025-04-19 00:28:16 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 306 ms / 5,000 ms |
コード長 | 1,372 bytes |
コンパイル時間 | 3,467 ms |
コンパイル使用メモリ | 287,460 KB |
実行使用メモリ | 49,900 KB |
最終ジャッジ日時 | 2025-04-19 00:28:30 |
合計ジャッジ時間 | 12,000 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; template<class T>using V=vector<T>; template<class T>using VV=V<V<T>>;//B(n,V<int>(n)) const ll INF=1e18; struct Edge{ int to; ll w; Edge(int to,ll w):to(to),w(w){} }; using Graph=VV<Edge>; using pli=pair<ll,int>; template<class T> bool chmin(T& a,T b){ return ((a>b)?(a=b,true):(false)); } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m,k; cin>>n>>m>>k; V<ll> C(m); rep(i,m) cin>>C[i]; Graph G(n*(k+1)); rep(i,m){ int a,b; cin>>a>>b; a--,b--; rep(j,k+1){ G[a+n*j].push_back(Edge(b+n*j,C[i])); G[b+n*j].push_back(Edge(a+n*j,C[i])); } rep(j,k){ G[a+n*j].push_back(Edge(b+n*(j+1),0)); G[b+n*j].push_back(Edge(a+n*(j+1),0)); } } V<ll> dist(n*(k+1),INF); int s=0; dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } ll ans=INF; rep(j,k+1) ans=min(ans,dist[n-1+n*j]); if(ans==INF) cout<<-1<<endl; else cout<<ans<<endl; return 0; }