結果
| 問題 |
No.2739 Time is money
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 13:22:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 286 ms / 2,000 ms |
| コード長 | 876 bytes |
| コンパイル時間 | 2,333 ms |
| コンパイル使用メモリ | 207,320 KB |
| 最終ジャッジ日時 | 2025-02-21 06:27:03 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, u, v;
ll x, c, t;
cin >> n >> m >> x;
vector<vector<pair<int,ll>>> g(n);
for(int i = 0; i < m; i++){
cin >> u >> v >> c >> t;
u--, v--;
g[u].emplace_back(v, c + t * x);
g[v].emplace_back(u, c + t * x);
}
vector<ll> dp(n, 1ll << 62);
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.emplace(0, 0);
dp[0] = 0;
while(!pq.empty()){
tie(t, v) = pq.top();
pq.pop();
if(t > dp[v]) continue;
for(auto [u, w] : g[v]){
if(t + w >= dp[u]) continue;
dp[u] = t + w;
pq.emplace(dp[u], u);
}
}
cout << (dp.back() >> 62 ? -x : dp.back() + x - 1) / x << '\n';
}