QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#155325 | #2169. 'S No Problem | warwolf# | WA | 2ms | 5980kb | C++23 | 1.3kb | 2023-09-01 15:52:50 | 2023-09-01 15:52:51 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 100086
using namespace std;
int n;
vector<pair<int, int> > v[maxn];
int ans, f[maxn], g[maxn], h[maxn];
void dfs(int i, int fa){
int mx = 0, id = 0, sx = 0;
for(auto it : v[i]){
int to = it.first, co = it.second;
if(to == fa) continue;
dfs(to, i);
if(g[to] >= mx) sx = mx, mx = g[to], id = to;
else sx = max(sx, g[to]);
}
f[i] = mx;
int fmx = 0, hmx = 0;
for(auto it : v[i]){
int to = it.first, co = it.second;
if(to == fa) continue;
ans = max(ans, g[i] + g[to]);
g[i] = max(g[i], g[to]);
int fval = f[to] + co;
int hval = h[to] + co;
ans = max(ans, fval + hmx);
ans = max(ans, fmx + hval);
g[i] = max(g[i], hmx + hval);
fmx = max(fmx, fval);
hmx = max(hmx, hval);
}
for(auto it : v[i]){
int to = it.first, co = it.second;
if(to == fa) continue;
int fval = f[to] + co + (id == to ? sx : mx);
int hval = h[to] + co;
f[i] = max(f[i], fval);
h[i] = max(h[i], hval);
}
// printf("%d %d %d %d--\n", i, f[i], g[i], h[i]);
}
int main(){
scanf("%d", &n);
for(int i = 1;i < n;i++){
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
v[x].push_back({y, z});
v[y].push_back({x, z});
}
dfs(1, 0);
// printf("%d--\n", ans);
ans = -ans;
for(int i = 1;i <= n;i++) for(auto it : v[i]) ans += it.second;
printf("%d", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5980kb
input:
5 1 2 1 1 3 2 1 4 3 1 5 4
output:
13
result:
wrong answer 1st lines differ - expected: '10', found: '13'