QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155325#2169. 'S No Problemwarwolf#WA 2ms5980kbC++231.3kb2023-09-01 15:52:502023-09-01 15:52:51

Judging History

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

  • [2023-09-01 15:52:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5980kb
  • [2023-09-01 15:52:50]
  • 提交

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

詳細信息

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'