QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#360447 | #6350. MIT | Glacia | WA | 65ms | 6248kb | C++23 | 1.3kb | 2024-03-21 19:44:42 | 2024-03-21 19:44:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, u, v, w, a[100471], fa[100471], cnt[100471], ans[100471];
vector<pair<int, int>> G[100471], V;
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);
}
}
}
int find(int u) {
return u == fa[u] ? u : fa[u] = find(fa[u]);
}
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>>());
a[n - 1] = n;
for (int j = n - 2; j >= 0; j--) {
a[j] = (V[j].second == V[j + 1].second ? a[j + 1] : j + 1);
}
iota(fa, fa + n + 1, 0);
memset(cnt, 0, sizeof(cnt));
int res = 0, pos = 0;
for (int j = 0; j < n; j++) {
while (find(pos) > pos) {
pos++;
}
int x = pos;
if (cnt[V[pos].second] > j / 2) {
x = find(a[j]);
if (x == n) {
break;
}
}
auto [d, v] = V[x];
cnt[v]++;
res += d;
fa[x] = x + 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: 6036kb
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: 65ms
memory: 6248kb
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 97613382343 146268479567 194782758998 243120633399 291469532829 339657517459 387815645995 435821231944 483717446257 531476208289 579182975985 626793764008 674259794140 721617453738 768890961261 816032104456 863044440224 909993041382 956790589086 1003491332151 1050093110804 1096582356539 ...
result:
wrong answer 2nd numbers differ - expected: '97562386542', found: '97613382343'