QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56317#2169. 'S No ProblemUT_aka_Is#WA 1ms6212kbC++983b2022-10-18 18:26:062022-10-18 18:26:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-18 18:26:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6212kb
  • [2022-10-18 18:26:06]
  • 提交

answer

#include <bits/stdc++.h>
#define SIZE 100005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector <P> vec[SIZE];
int m1[SIZE],m2[SIZE];

void dfs(int v=0,int p=-1){
	m1[v]=m2[v]=0;
	for(int i=0;i<vec[v].size();i++){
		int to=vec[v][i].first;
		int cost=vec[v][i].second;
		if(to!=p){
			dfs(to,v);
			int c=cost+m1[to];
			if(m1[v]<c) swap(c,m1[v]);
			if(m2[v]<c) swap(c,m2[v]);
		}
	}
}
int dfs2(int v=0,int p=-1,int d1=0,int d2=0){
	int ret=d2+m1[v]+m2[v];
	for(int i=0;i<vec[v].size();i++){
		int to=vec[v][i].first;
		int cost=vec[v][i].second;
		if(to!=p){
			int a=m1[v];
			if(m1[to]+cost==a){
				a=m2[v];
			}
			int b=d1;
			if(a<b) swap(a,b);
			ret=max(ret,dfs2(to,v,a+cost,a+b));
		}
	}
	return ret;
}
int main(){
	int n;
	scanf("%d",&n);
	int ret=0;
	for(int i=0;i<n-1;i++){
		int a,b,d;
		scanf("%d%d%d",&a,&b,&d);a--,b--;
		vec[a].push_back(P(b,d));
		vec[b].push_back(P(a,d));
		ret+=2*d;
	}
	dfs();
	ret-=dfs2();
	printf("%d\n",ret);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6212kb

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'