QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56321 | #2169. 'S No Problem | UT_aka_Is# | WA | 4ms | 6128kb | C++ | 1.4kb | 2022-10-18 18:35:28 | 2022-10-18 18:35:31 |
Judging History
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],m3[SIZE];
int dp[SIZE];
void dfs(int v=0,int p=-1){
m1[v]=m2[v]=m3[v]=0;
dp[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);
dp[v]=max(dp[v],dp[to]);
int c=cost+m1[to];
if(m1[v]<c) swap(c,m1[v]);
if(m2[v]<c) swap(c,m2[v]);
if(m3[v]<c) swap(c,m3[v]);
}
}
dp[v]=max(dp[v],m1[v]+m2[v]);
}
int dfs2(int v=0,int p=-1,int d1=0,int d2=0){
int ret=d2+dp[v];
int x=0,y=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){
int c=dp[to];
if(x<c) swap(x,c);
if(y<c) swap(y,c);
}
}
ret=max(ret,x+y);
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],b=m2[v];
if(m1[to]+cost==a){
a=m2[v],b=m3[v];
} else if(m1[to]+cost==b){
b=m3[v];
}
int c=d1;
if(b<c) swap(b,c);
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: 4ms
memory: 6128kb
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'