結果

問題 No.2387 Yokan Factory
ユーザー kwm_tkwm_t
提出日時 2023-07-21 22:01:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 526 ms / 5,000 ms
コード長 1,966 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 211,716 KB
実行使用メモリ 16,636 KB
最終ジャッジ日時 2023-10-21 22:02:43
合計ジャッジ時間 7,882 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,384 KB
testcase_01 AC 5 ms
8,384 KB
testcase_02 AC 4 ms
8,380 KB
testcase_03 AC 4 ms
8,384 KB
testcase_04 AC 4 ms
8,384 KB
testcase_05 AC 4 ms
8,384 KB
testcase_06 AC 4 ms
8,384 KB
testcase_07 AC 4 ms
8,384 KB
testcase_08 AC 5 ms
8,384 KB
testcase_09 AC 4 ms
8,384 KB
testcase_10 AC 4 ms
8,384 KB
testcase_11 AC 5 ms
8,384 KB
testcase_12 AC 5 ms
8,384 KB
testcase_13 AC 5 ms
8,384 KB
testcase_14 AC 4 ms
8,384 KB
testcase_15 AC 191 ms
16,636 KB
testcase_16 AC 96 ms
15,608 KB
testcase_17 AC 309 ms
15,632 KB
testcase_18 AC 228 ms
14,360 KB
testcase_19 AC 322 ms
13,044 KB
testcase_20 AC 265 ms
12,360 KB
testcase_21 AC 526 ms
14,204 KB
testcase_22 AC 234 ms
12,004 KB
testcase_23 AC 362 ms
12,892 KB
testcase_24 AC 137 ms
12,460 KB
testcase_25 AC 187 ms
10,880 KB
testcase_26 AC 425 ms
13,416 KB
testcase_27 AC 504 ms
14,144 KB
testcase_28 AC 5 ms
8,492 KB
testcase_29 AC 7 ms
8,544 KB
testcase_30 AC 6 ms
8,516 KB
testcase_31 AC 6 ms
8,468 KB
testcase_32 AC 4 ms
8,436 KB
testcase_33 AC 5 ms
8,436 KB
testcase_34 AC 7 ms
8,536 KB
testcase_35 AC 5 ms
8,508 KB
testcase_36 AC 4 ms
8,436 KB
testcase_37 AC 4 ms
8,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<long long,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
	int to;
	long long a;
	long long b;
	Edge(int _to, long long _a, long long _b) :to(_to), a(_a), b(_b) {}
};
vector<Edge>g[200005];
bool dikstra(int n, long long mid, long long x) {
	vector<long long> dp(n, LINF * 2);
	priority_queue<P, vector<P>, greater<P>> q;
	q.push({ 0, 0 });
	dp[0] = 0;
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		long long a = tmp.first;
		int pos = tmp.second;
		if (a > dp[pos]) continue;
		for (Edge e : g[pos]) {
			long long na = a + e.a;
			if (e.b < mid)continue;
			int npos = e.to;
			if (chmin(dp[npos], na)) q.push({ na, npos });
		}
	}
	return dp[n - 1] <= x;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	long long x; cin >> x;
	rep(i, m) {
		int u, v; cin >> u >> v; u--, v--;
		long long a, b; cin >> a >> b;
		g[u].emplace_back(v, a, b);
		g[v].emplace_back(u, a, b);
	}
	long long ok = -1;
	long long ng = LINF + 1;
	while (1 < abs(ok - ng)) {
		long long mid = (ng + ok) / 2;
		auto check = [&]() {
			return dikstra(n, mid, x);
		};
		if (check()) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	return 0;
}
0