結果
問題 |
No.3111 Toll Optimization
|
ユーザー |
![]() |
提出日時 | 2025-04-18 22:12:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 170 ms / 5,000 ms |
コード長 | 2,236 bytes |
コンパイル時間 | 1,829 ms |
コンパイル使用メモリ | 145,212 KB |
実行使用メモリ | 17,268 KB |
最終ジャッジ日時 | 2025-04-18 22:12:11 |
合計ジャッジ時間 | 8,483 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <iostream> #include <algorithm> #include <functional> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <array> #include<utility> #include<stack> #include <iomanip> //#include<atcoder/all> //using namespace atcoder; using namespace std; #define P pair<int,int> #define Graph vector<vector<int>> #define float long double #define rep(i,a,b) for(int i=(a);i<(b);++i) #define repi(itr,m) for(auto itr=(m).begin();itr!=(m).end();itr++) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define vi vector<int> #define int long long const int INF=1e18; int dx[8]={0,1,0,-1,-1,-1,1,1}; int dy[8]={1,0,-1,0,-1,1,-1,1}; template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false));} template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false));} struct point{ int x,y; }; void yn(bool t){ if(t)cout<<"Yes"<<endl; else cout<<"No"<<endl; } int solve(){ int n,m,k;cin>>n>>m>>k; vector<int>c(m+1); rep(i,1,m+1)cin>>c[i]; vector<vector<P>>g(n+1); rep(i,1,m+1){ int u,v;cin>>u>>v; g[u].push_back({v,c[i]}); g[v].push_back({u,c[i]}); } vector<vector<int>>dist(k+1,vector<int>(n+1,INF)); dist[0][1]=0; priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>pq; pq.push({0,0,1}); while(!pq.empty()){ auto [val,num,p]=pq.top();pq.pop(); if(dist[num][p]<val)continue; if(num!=k){ for(auto [e,cost]:g[p]){ if(dist[num+1][e]>val){ dist[num+1][e]=val; pq.push({val,num+1,e}); } } } for(auto [e,cost]:g[p]){ if(dist[num][e]>val+cost){ dist[num][e]=val+cost; pq.push({val+cost,num,e}); } } } int ans=INF; rep(i,0,k+1)ans=min(ans,dist[i][n]); if(ans==INF){ cout<<-1<<endl; return 0; } cout<<ans<<endl; assert(true); return 0; } signed main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); solve(); }