結果
問題 | No.2739 Time is money |
ユーザー |
|
提出日時 | 2024-04-20 10:43:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 530 ms / 2,000 ms |
コード長 | 1,957 bytes |
コンパイル時間 | 2,359 ms |
コンパイル使用メモリ | 205,136 KB |
最終ジャッジ日時 | 2025-02-21 06:10:46 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include<bits/stdc++.h>#define overload(a,b,c,d,...) d#define rep1(a) for(ll _=0;_<(ll)a;++_)#define rep2(i,a) for(ll i=0;i<(ll)a;++i)#define rep3(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)#define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i)#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)#define eb emplace_back#define pb push_back#define all(v) (v).begin(),(v).end()#define rall(v) (v).rbegin(),(v).rend()#define lb(v,x) (lower_bound(all(v),x)-(v).begin())#define ub(v,x) (upper_bound(all(v),x)-(v).begin())using namespace std;using ll=long long;using vl=vector<ll>;using ld=long double;using i128=__int128_t;template<typename T,typename U>inline static constexpr bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}template<typename T,typename U>inline static constexpr bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}static constexpr ll inf=numeric_limits<ll>::max()/2;struct IOSetup{IOSetup(){ios::sync_with_stdio(false);cin.tie(nullptr);}};static constexpr ll mod=998244353;int main(){ll n,m,x;cin>>n>>m>>x;vector<vector<array<ll,3>>>g(n);rep(i,m){ll u,v,c,t;cin>>u>>v>>c>>t;u--,v--;g[u].pb({v,c,t});g[v].pb({u,c,t});}vector<pair<ll,ll>>dist(n,{inf,inf});dist[0]={0,0};priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll>>,greater<>>pq;pq.push({dist[0],0});while(!pq.empty()){auto [d,v]=pq.top();pq.pop();if(dist[v]<d)continue;for(auto [u,c,t]:g[v]){pair<ll,ll>nxt={dist[v].first+t,dist[v].second+c};nxt.first+=nxt.second/x;nxt.second%=x;if(chmin(dist[u],nxt))pq.push({dist[u],u});}}ll ans=dist[n-1].first+(dist[n-1].second==0?0:1);if(ans>=inf){cout<<-1<<endl;}else cout<<ans<<endl;}