結果

問題 No.2739 Time is money
ユーザー kenken714kenken714
提出日時 2024-04-13 22:40:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 1,184 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 204,164 KB
実行使用メモリ 21,676 KB
最終ジャッジ日時 2024-04-14 11:30:22
合計ジャッジ時間 10,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,028 KB
testcase_01 AC 4 ms
10,084 KB
testcase_02 AC 186 ms
15,988 KB
testcase_03 AC 398 ms
19,944 KB
testcase_04 AC 181 ms
15,944 KB
testcase_05 AC 246 ms
17,132 KB
testcase_06 AC 322 ms
20,280 KB
testcase_07 AC 405 ms
20,488 KB
testcase_08 AC 498 ms
20,600 KB
testcase_09 AC 420 ms
20,676 KB
testcase_10 AC 340 ms
20,304 KB
testcase_11 AC 489 ms
20,640 KB
testcase_12 AC 338 ms
19,540 KB
testcase_13 AC 343 ms
19,376 KB
testcase_14 AC 326 ms
19,456 KB
testcase_15 AC 259 ms
21,676 KB
testcase_16 AC 253 ms
19,312 KB
testcase_17 AC 381 ms
20,788 KB
testcase_18 AC 412 ms
20,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll d[210000]; 
struct edge { ll to, cost; };
vector<edge> g[210000];
void dijkstra(ll a) {
	priority_queue<P, vector<P>, greater<P> > q;
	fill(d, d + 210000, INF);
	d[a] = 0;
	q.push(P(0, a));
	while (!q.empty()) {
		P p = q.top();
		q.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		REP(i, g[v].size()) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}
int main(){
    ll n, m, x;
    cin >> n >> m >> x;
    REP(i, m){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        g[a].push_back({b, c + x * d});
        g[b].push_back({a, c + x * d});
    }
    dijkstra(0);
    cout << (d[n - 1] == INF ? -1 : (d[n - 1] + x - 1) / x) << endl;
}
0