結果
問題 | No.2739 Time is money |
ユーザー |
|
提出日時 | 2024-04-20 19:38:29 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 2,703 bytes |
コンパイル時間 | 2,743 ms |
コンパイル使用メモリ | 262,536 KB |
実行使用メモリ | 22,016 KB |
最終ジャッジ日時 | 2024-10-12 17:31:22 |
合計ジャッジ時間 | 6,525 ms |
ジャッジサーバーID (参考情報) |
judge / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)#define rreps(i, n) for(int i=((int)(n)); i>0; --i)#define all(v) (v).begin(), (v).end()using namespace std;using ll = long long;using ull = unsigned long long;using vi = vector<int>;using vvi = vector<vector<int>>;using vvvi = vector<vector<vector<int>>>;using vl = vector<ll>;using vvl = vector<vector<ll>>;using vvvl = vector<vector<vector<ll>>>;using vs = vector<string>;using pi = pair<int, int>;using pl = pair<ll, ll>;template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }template<class T>bool chmaxeq(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }template<class T>bool chmineq(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }bool yes(bool a) { cout << (a?"yes":"no") << endl; return a; }bool Yes(bool a) { cout << (a?"Yes":"No") << endl; return a; }bool YES(bool a) { cout << (a?"YES":"NO") << endl; return a; }void _main();int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); _main(); return 0; }long long INF = 1LL << 60;using P = pair<long long, long long>;struct Edge {long long to, cost;Edge(long long to, long long cost) : to(to), cost(cost) {}};struct Graph {vector<vector<Edge>> g;vector<long long> d;vector<long long> prev;Graph(long long n) {g.resize(n);d.assign(n, INF);prev.assign(n, -1);}void add_edge(long long from, long long to, long long cost) {g[from].push_back(Edge(to, cost));}void add_indirected_edge(long long from, long long to, long long cost) {add_edge(from, to, cost);add_edge(to, from, cost);}void dijkstra(long long s) {d[s] = 0;priority_queue<P, vector<P>, greater<P>> q;q.push({0, s});while (!q.empty()) {P p = q.top();q.pop();long long v = p.second;if (d[v] < p.first) continue;for (auto &e : g[v]) {if (d[e.to] > d[v]+e.cost) {d[e.to] = d[v]+e.cost;prev[e.to] = v;q.push({d[e.to], e.to});}}}}vector<long long> get_path(long long t) {vector<long long> path;for (long long cur = t; cur != -1; cur = prev[cur]) {path.push_back(cur);}reverse(path.begin(), path.end());return path;}};void _main() {ll N, M, X; cin >> N >> M >> X;Graph g(N);rep(i, M) {ll u, v, C, T; cin >> u >> v >> C >> T;u--; v--;g.add_indirected_edge(u, v, C+T*X);}g.dijkstra(0);cout << (g.d[N-1]==INF?-1:(g.d[N-1]+X-1)/X) << endl;}