結果
| 問題 |
No.2739 Time is money
|
| コンテスト | |
| ユーザー |
zatsu308
|
| 提出日時 | 2024-04-20 13:40:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 270 ms / 2,000 ms |
| コード長 | 1,694 bytes |
| コンパイル時間 | 2,237 ms |
| コンパイル使用メモリ | 205,888 KB |
| 最終ジャッジ日時 | 2025-02-21 06:30:09 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;
template<ll mod>
struct Mint {
using M=Mint; ll v;
M& put(ll x) { v=(x<mod)?x:x-mod; return *this; }
Mint(ll x=0) { put(x%mod+mod); }
M operator+(M m) {return M().put(v+m.v);}
M operator-(M m) {return M().put(v+mod-m.v);}
M operator*(M m) {return M().put(v*m.v%mod);}
M operator/(M m) {return M().put(v*m.inv().v%mod);}
// BEGIN IGNORE
M operator+=(M m) { return put(v+m.v); }
M operator-=(M m) { return put(v+mod-m.v); }
M operator*=(M m) { return put(v*m.v%mod); }
M operator/=(M m) { return put(v*m.inv().v%mod); }
// END IGNORE
bool operator==(M m) { return v==m.v; }
M pow(ll m) const {
M x=v, res=1;
while (m) {
if (m&1) res=res*x;
x=x*x; m>>=1;
}
return res;
}
M inv() { return pow(mod-2); }
};
using mint = Mint<mod>;
int main(){
cin.tie(0);
cin.sync_with_stdio(0);
int n, m, x;
cin >> n >> m >> x;
vector<vector<pair<ll,ll>>> edges(n);
for(int i = 0; i < m; ++i){
int u, v, c, t;
cin >> u >> v >> c >> t;
--u, --v;
edges[u].emplace_back(v, c + 1ll * t * x);
edges[v].emplace_back(u, c + 1ll * t * x);
}
vector<ll> dp(n, 1e18);
dp[0] = 0;
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<>> que;
que.emplace(0, 0);
while(!que.empty()){
auto [d, pos] = que.top();
que.pop();
if(dp[pos] != d)continue;
for(auto [to, cos] : edges[pos]){
if(dp[to] > d + cos){
dp[to] = d + cos;
que.emplace(d + cos, to);
}
}
}
if(dp.back() == 1e18){
cout << -1 << endl;
}
else{
cout << (dp.back() + x - 1) / x << endl;
}
}
zatsu308