QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#360486#6350. MITGlaciaWA 68ms5020kbC++232.3kb2024-03-21 20:12:482024-03-21 20:12:49

Judging History

你现在查看的是最新测评结果

  • [2024-03-21 20:12:49]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:5020kb
  • [2024-03-21 20:12:48]
  • 提交

answer

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

#define int long long

int n, u, v, w, cnt[100471], ans[100471];
vector<pair<int, int>> G[100471], V;
pair<tuple<int, int, int>, tuple<int, int, int>> val[100471];

void dfs(int u, int f, int x, int y) {
	V.emplace_back(y, x);
	for (auto [v, w] : G[u]) {
		if (v != f) {
			dfs(v, u, x, y + w);
		}
	}
}

pair<tuple<int, int, int>, tuple<int, int, int>> merge(pair<tuple<int, int, int>, tuple<int, int, int>> a, pair<tuple<int, int, int>, tuple<int, int, int>> b) {
	if (a.first < b.first) {
		swap(a, b);
	}
	return get<2>(b.first) != get<2>(a.first) && b.first > a.second ? make_pair(a.first, b.first) : a;
}

void build(int l, int r, int o) {
	if (l == r) {
		val[o] = {{V[l].first, l, V[l].second}, {-1, n, 0}};
		return;
	}
	int mid = (l + r) / 2;
	build(l, mid, o << 1);
	build(mid + 1, r, o << 1 | 1);
	val[o] = merge(val[o << 1], val[o << 1 | 1]);
}

void remove(int x, int l, int r, int o) {
	if (l == r) {
		val[o] = {{-1, n, 0}, {-1, n, -1}};
		return;
	}
	int mid = (l + r) / 2;
	if (x <= mid) {
		remove(x, l, mid, o << 1);
	} else {
		remove(x, mid + 1, r, o << 1 | 1);
	}
	val[o] = merge(val[o << 1], val[o << 1 | 1]);
}

pair<tuple<int, int, int>, tuple<int, int, int>> query(int ll, int rr, int l, int r, int o) {
	if (ll <= l && r <= rr) {
		return val[o];
	} else if (ll <= r && l <= rr) {
		int mid = (l + r) / 2;
		return merge(query(ll, rr, l, mid, o << 1), query(ll, rr, mid + 1, r, o << 1 | 1));
	} else {
		return {{-1, n, 0}, {-1, n, -1}};
	}
}

signed main() {
	scanf("%lld", &n);
	for (int i = 1; i < n; i++) {
		scanf("%lld%lld%lld", &u, &v, &w);
		G[u].emplace_back(v, w);
		G[v].emplace_back(u, w);
	}
	for (int i = 1; i <= n; i++) {
		V = {{0, i}};
		for (auto [v, w] : G[i]) {
			dfs(v, i, v, w);
		}
		sort(V.begin(), V.end(), greater<pair<int, int>>());
		memset(cnt, 0, sizeof(cnt));
		build(0, n - 1, 1);
		int res = 0, pos = 0;
		for (int j = 0; j < n; j++) {
			auto [d, u, v] = (cnt[get<2>(val[1].first)] > j / 2 ? val[1].second : val[1].first);
			if (u == n) {
				break;
			}
			cnt[v]++;
			res += d;
			remove(u, 0, n - 1, 1);
			ans[j + 1] = max(ans[j + 1], res);
		}
	}
	for (int i = 2; i <= n; i += 2) {
		printf("%lld ", ans[i]);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4784kb

input:

7
1 3 99
2 3 82
3 4 4
4 5 43
5 6 5
4 7 3

output:

181 280 287 

result:

ok 3 number(s): "181 280 287"

Test #2:

score: -100
Wrong Answer
time: 68ms
memory: 5020kb

input:

1000
328 12 58771429
881 504 17030494
847 622 20805817
12 922 58532669
879 929 52585738
495 726 27873950
855 17 37971674
797 941 76999719
702 610 719916
479 127 97829887
731 557 55300256
282 615 88802280
651 318 64099880
540 51 6547869
896 54 87823596
674 879 80674008
77 691 54802376
193 851 7869172...

output:

48829042195 97562386542 146216474947 194713456438 243120633399 291394542517 339657517459 387785045812 435787622310 483691355869 531476208289 578959550298 626628469998 674169104873 721577617950 768862531418 816032104456 863044440224 909960999950 956790589086 1003444852919 1050093110804 1096582356539 ...

result:

wrong answer 12th numbers differ - expected: '579153483709', found: '578959550298'