結果
問題 | No.2739 Time is money |
ユーザー |
![]() |
提出日時 | 2024-04-25 17:31:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 252 ms / 2,000 ms |
コード長 | 1,191 bytes |
コンパイル時間 | 2,313 ms |
コンパイル使用メモリ | 206,624 KB |
最終ジャッジ日時 | 2025-02-21 09:00:32 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;vector<ll> dijkstra(vector<vector<pair<ll, ll>>> &E, ll start){ll N = E.size();ll from, alt, d;pq<pair<ll, ll>> que;vector<ll> dist(N, 1e18);vector<bool> vst(N);dist[start] = 0;que.push({0, start});while(!que.empty()){tie(d, from) = que.top();que.pop();if (vst[from]) continue;vst[from] = 1;for (auto [to, C] : E[from]){alt = d + C;if (alt < dist[to]){dist[to] = alt;que.push({dist[to], to});}}}return dist;}int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);ll N, M, X, A, B, C, T;cin >> N >> M >> X;vector<vector<pair<ll, ll>>> E(N);for (int i=0; i<M; i++){cin >> A >> B >> C >> T;A--; B--;E[A].push_back({B, C+T*X});E[B].push_back({A, C+T*X});}vector<ll> dist = dijkstra(E, 0);cout << (dist[N-1] == 1e18 ? -1 : (dist[N-1]+X-1)/X) << endl;return 0;}