結果

問題 No.1898 Battle and Exchange
ユーザー polylogKpolylogK
提出日時 2022-01-11 08:07:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 931 ms / 5,000 ms
コード長 1,736 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 212,156 KB
実行使用メモリ 15,172 KB
最終ジャッジ日時 2023-09-02 21:36:15
合計ジャッジ時間 27,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 10 ms
4,368 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 3 ms
4,368 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 8 ms
4,368 KB
testcase_18 AC 34 ms
4,992 KB
testcase_19 AC 68 ms
5,892 KB
testcase_20 AC 49 ms
6,248 KB
testcase_21 AC 261 ms
11,008 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 4 ms
4,368 KB
testcase_28 AC 4 ms
4,372 KB
testcase_29 AC 9 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 1 ms
4,368 KB
testcase_32 AC 58 ms
6,012 KB
testcase_33 AC 102 ms
8,104 KB
testcase_34 AC 41 ms
5,504 KB
testcase_35 AC 76 ms
6,668 KB
testcase_36 AC 57 ms
6,492 KB
testcase_37 AC 30 ms
4,508 KB
testcase_38 AC 545 ms
15,172 KB
testcase_39 AC 134 ms
12,628 KB
testcase_40 AC 623 ms
13,740 KB
testcase_41 AC 141 ms
12,240 KB
testcase_42 AC 9 ms
4,372 KB
testcase_43 AC 97 ms
9,212 KB
testcase_44 AC 2 ms
4,368 KB
testcase_45 AC 16 ms
4,372 KB
testcase_46 AC 88 ms
5,956 KB
testcase_47 AC 15 ms
4,372 KB
testcase_48 AC 19 ms
4,444 KB
testcase_49 AC 4 ms
4,368 KB
testcase_50 AC 3 ms
4,368 KB
testcase_51 AC 4 ms
4,368 KB
testcase_52 AC 6 ms
4,368 KB
testcase_53 AC 29 ms
4,944 KB
testcase_54 AC 27 ms
5,456 KB
testcase_55 AC 45 ms
5,264 KB
testcase_56 AC 38 ms
5,812 KB
testcase_57 AC 574 ms
11,852 KB
testcase_58 AC 479 ms
12,032 KB
testcase_59 AC 346 ms
11,792 KB
testcase_60 AC 931 ms
11,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

int main() {
	int n, m; scanf("%d%d", &n, &m);
	std::vector<int> u(m), v(m), a(n), b(n), c(n);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &u[i], &v[i]); u[i]--; v[i]--;

		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	for(int i = 0; i < n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);

	if(n == 1) {
		// no case exist
	}

	std::vector<i64> d(n);
	for(int i = 0; i < n; i++) d[i] = (i64)a[i] + b[i] + c[i];

	for(int i = 0; i < n; i++) {
		int min = std::min({a[i], b[i], c[i]});
		int max = std::max({a[i], b[i], c[i]});
		a[i] = min;
		b[i] = d[i] - min - max;
		c[i] = max;
	}

	int min_v = g[0][0];
	for(auto v: g[0]) {
		if(d[v] < d[min_v]) min_v = v;
	}

	auto f = [&](i64 C, i64 B = 1, i64 A = 1) -> bool {
		if(d[0] >= A + B + C) return false;

		auto update = [&](int x) {
			if(C < x) {
				A = B;
				B = C;
				C = x;
			} else if(B < x) {
				A = B;
				B = x;
			} else if(A < x) {
				A = x;
			}
		};

		update(c[0]);

		if(d[min_v] >= A + B + C) return false;

		A = 1; B = 1;

		using P = std::pair<i64, int>;
		std::priority_queue<P, std::vector<P>, std::greater<>> qu;
		qu.push({d[0], 0});

		std::vector<int> used(n); used[0] = true;
		while(!qu.empty()) {
			auto [sum, v] = qu.top(); qu.pop();
			if(sum >= A + B + C) return false;
			if(v == n - 1) return true;

			update(a[v]);
			update(b[v]);
			update(c[v]);

			for(int to: g[v]) {
				if(used[to]) continue; used[to] = true;

				qu.push({d[to], to});
			}
		}
		return false;
	};

	i64 ng = 1, ok = 3'000'000'000LL;
	while(ok - ng > 1) {
		i64 mid = ng + (ok - ng) / 2;

		if(f(mid)) ok = mid;
		else ng = mid;
	}

	printf("%lld 1 1\n", ok);
	return 0;
}
0