結果

問題 No.1898 Battle and Exchange
ユーザー polylogKpolylogK
提出日時 2021-12-24 01:42:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,996 bytes
コンパイル時間 4,242 ms
コンパイル使用メモリ 212,236 KB
実行使用メモリ 13,304 KB
最終ジャッジ日時 2023-10-22 04:26:58
合計ジャッジ時間 16,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 8 ms
4,396 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 21 ms
5,136 KB
testcase_19 AC 30 ms
6,192 KB
testcase_20 AC 31 ms
6,456 KB
testcase_21 AC 86 ms
10,680 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 9 ms
4,436 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 28 ms
5,928 KB
testcase_33 AC 54 ms
8,040 KB
testcase_34 AC 23 ms
5,664 KB
testcase_35 AC 37 ms
6,984 KB
testcase_36 WA -
testcase_37 AC 10 ms
4,620 KB
testcase_38 AC 92 ms
13,304 KB
testcase_39 AC 58 ms
11,640 KB
testcase_40 AC 82 ms
12,420 KB
testcase_41 AC 53 ms
11,176 KB
testcase_42 AC 6 ms
4,348 KB
testcase_43 AC 55 ms
9,096 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 8 ms
4,348 KB
testcase_46 AC 31 ms
6,192 KB
testcase_47 AC 6 ms
4,348 KB
testcase_48 AC 11 ms
4,612 KB
testcase_49 AC 3 ms
4,348 KB
testcase_50 AC 4 ms
4,348 KB
testcase_51 AC 3 ms
4,348 KB
testcase_52 AC 5 ms
4,348 KB
testcase_53 AC 21 ms
5,252 KB
testcase_54 AC 23 ms
5,664 KB
testcase_55 AC 25 ms
5,564 KB
testcase_56 AC 28 ms
5,928 KB
testcase_57 AC 107 ms
11,472 KB
testcase_58 AC 104 ms
11,472 KB
testcase_59 AC 97 ms
11,472 KB
testcase_60 AC 97 ms
11,472 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<int> d(n);
	for(int i = 0; i < n; i++) d[i] = 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 A = 1, B = 1, C = d[0] - 1, ans = d[0] - 1; // A <= B <= C
	auto normalize = [&]() {
		int min = std::min({A, B, C});
		int max = std::max({A, B, C});
		B = A + B + C - min - max;
		A = min;
		C = max;
	};
	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]);

	{
		int v = g[0][0];
		for(int to: g[0]) if(d[v] > d[to]) v = to;

		if(A + B + C <= d[v]) { // 足りていない
			ans = C = d[v] - A - 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) { // 足りていない
			int diff = sum - A - B - C + 1;
			if(ans == A) {
				A += diff;
				ans += diff;
			} else if(ans == B) {
				B += diff;
				ans += diff;
			} else if(ans == C) {
				C += diff;
				ans += diff;
			} else {
				ans = A + diff;
				update(ans);
			}
			normalize();

			assert(A + B + C > sum);
		}

		if(v == n - 1) {
			printf("1 1 %d\n", ans);
			break;
		}

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