結果

問題 No.2387 Yokan Factory
ユーザー ripityripity
提出日時 2023-07-21 21:53:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 434 ms / 5,000 ms
コード長 1,036 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 216,896 KB
実行使用メモリ 10,620 KB
最終ジャッジ日時 2023-10-21 21:53:46
合計ジャッジ時間 7,098 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 231 ms
10,012 KB
testcase_16 AC 157 ms
10,372 KB
testcase_17 AC 358 ms
10,620 KB
testcase_18 AC 239 ms
9,632 KB
testcase_19 AC 287 ms
7,208 KB
testcase_20 AC 234 ms
6,784 KB
testcase_21 AC 421 ms
9,056 KB
testcase_22 AC 224 ms
6,508 KB
testcase_23 AC 326 ms
7,324 KB
testcase_24 AC 145 ms
6,808 KB
testcase_25 AC 192 ms
5,912 KB
testcase_26 AC 380 ms
7,808 KB
testcase_27 AC 434 ms
8,696 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int N, M;
	long long X;
	cin >> N >> M >> X;
	vector<int> u(M), v(M), b(M);
	vector<long long> a(M);
	vector<vector<int>> G(N, vector<int>());
	for( int i = 0; i < M; i++ ) {
		cin >> u[i] >> v[i] >> a[i] >> b[i];
		u[i]--, v[i]--;
		G[u[i]].push_back(i);
		G[v[i]].push_back(i);
	}
	auto f = [&](int W) -> bool {
		vector<bool> vis(N, false);
		vector<long long> d(N, 1LL<<59);
		priority_queue<pair<long long, int>> que;
		d[0] = 0;
		que.push(make_pair(0, 0));
		while( !que.empty() ) {
			auto [_d, cur] = que.top();
			que.pop();
			if( vis[cur] ) continue;
			vis[cur] = true;
			for( int i : G[cur] ) {
				int nxt = u[i]^v[i]^cur;
				if( !vis[nxt] && W <= b[i] && d[nxt] > d[cur]+a[i] ) {
					d[nxt] = d[cur]+a[i];
					que.push(make_pair(-d[nxt], nxt));
				}
			}
		}
		return d[N-1] <= X;
	};
	int ok = 0, ng = 1<<30;
	while( ok+1 < ng ) {
		int m = (ok+ng)/2;
		if( f(m) ) ok = m;
		else ng = m;
	}
	if( ok == 0 ) cout << -1 << endl;
	else cout << ok << endl;
}
0