67632023-12-18 21:48:23111Villanyautócpp17Accepted 60/60142ms4460 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

template<typename T>
using min_priority_queue = std::priority_queue<T, vector<T>, greater<T>>;

template<typename T, typename U>
bool ckmin(T& a, const U& b) {
	return b < a ? a = b, true : false;
}

#define A (int)1e12
#define B (int)1e18

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be1.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, M, K;
	cin >> N >> M >> K;
	vector<vector<pii>> g(N + 1);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	int l = 0, h = A;
	while (l < h) {
		int m = (l + h) / 2;
		// m possible?
		bool ok = true;
		for (int i = 1; i <= N; i++) {
			vector<int> v(N + 1, B);
			min_priority_queue<pii> pq;
			pq.emplace(0, i);
			v[i] = 0;
			while (!pq.empty()) {
				auto j = pq.top();
				pq.pop();
				if (j.first > v[j.second]) {
					continue;
				}
				for (pii p : g[j.second]) {
					if (p.second > m) {
						continue;
					}
					int c = v[j.second] + p.second;
					if (c % A > m) {
						c -= c % A;
						c += A + p.second;
					}
					if (ckmin(v[p.first], c)) {
						pq.emplace(v[p.first], p.first);
					}
				}
			}
			for (int j = 1; j <= N; j++) {
				if (v[j] / A >= K) {
					goto bad;
				}
			}
		}
		if (ok) {
			h = m;
		}
		else {
		bad:
			l = m + 1;
		}
	}
	cout << l << '\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base60/60
1Accepted0/03ms1832 KiB
2Accepted0/064ms2236 KiB
3Accepted1/117ms2392 KiB
4Accepted1/125ms2668 KiB
5Accepted1/128ms2856 KiB
6Accepted2/275ms2908 KiB
7Accepted2/2101ms3484 KiB
8Accepted2/2142ms3520 KiB
9Accepted1/113ms3208 KiB
10Accepted1/18ms3296 KiB
11Accepted1/16ms3540 KiB
12Accepted2/246ms3552 KiB
13Accepted2/234ms3472 KiB
14Accepted2/214ms3600 KiB
15Accepted3/335ms3700 KiB
16Accepted3/359ms3684 KiB
17Accepted2/28ms3604 KiB
18Accepted2/225ms3876 KiB
19Accepted2/225ms3912 KiB
20Accepted2/229ms4028 KiB
21Accepted2/217ms3980 KiB
22Accepted2/28ms4172 KiB
23Accepted3/334ms4212 KiB
24Accepted3/390ms4304 KiB
25Accepted3/390ms4120 KiB
26Accepted3/3129ms4308 KiB
27Accepted3/374ms4340 KiB
28Accepted3/343ms4244 KiB
29Accepted3/329ms4372 KiB
30Accepted3/339ms4460 KiB