結果

問題 No.2739 Time is money
ユーザー rii922rii922
提出日時 2024-04-20 19:38:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 2,703 bytes
コンパイル時間 3,902 ms
コンパイル使用メモリ 289,220 KB
実行使用メモリ 22,200 KB
最終ジャッジ日時 2024-04-20 19:38:39
合計ジャッジ時間 8,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 86 ms
14,720 KB
testcase_03 AC 173 ms
18,484 KB
testcase_04 AC 81 ms
14,016 KB
testcase_05 AC 115 ms
13,696 KB
testcase_06 AC 148 ms
16,508 KB
testcase_07 AC 236 ms
21,520 KB
testcase_08 AC 231 ms
21,632 KB
testcase_09 AC 259 ms
21,896 KB
testcase_10 AC 174 ms
21,264 KB
testcase_11 AC 236 ms
22,016 KB
testcase_12 AC 171 ms
20,596 KB
testcase_13 AC 163 ms
20,368 KB
testcase_14 AC 155 ms
20,460 KB
testcase_15 AC 110 ms
19,240 KB
testcase_16 AC 111 ms
17,992 KB
testcase_17 AC 222 ms
22,024 KB
testcase_18 AC 231 ms
22,200 KB
testcase_19 AC 132 ms
18,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0