# bzoj 3677

$f[x][0]=\sum max(f[to][0],f[to][1]+edge[i].val)$

$f[x][1]=f[x][0]+max(f[to][0]+edge[i].val-max(f[to][0],f[to][1]+edge[i].val)$

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int f[200005][3];
int g[200005];
int n;
struct Edge
{
int nxt;
int to;
int val;
}edge[400005];
int cnt=1;
int ans=0;
{
edge[cnt].to=r;
edge[cnt].val=w;
}
void dfs(int x,int fx)
{
f[x][1]=f[x][2]=-0x3f3f3f3f;
{
int to=edge[i].to;
if(to==fx)continue;
dfs(to,x);
int v=g[to]+edge[i].val-max(g[to],g[to]+f[to][1]+edge[i].val);
if(v>f[x][1])f[x][2]=f[x][1],f[x][1]=v;
else if(v>f[x][2])f[x][2]=v;
g[x]+=max(g[to],g[to]+f[to][1]+edge[i].val);
}
}
void redfs(int x,int fx)
{
ans=max(ans,g[x]);
{
int to=edge[i].to;
if(to==fx)continue;
int w2=g[to],o1=f[to][1],o2=f[to][2];
int gg=g[x]-max(g[to],g[to]+f[to][1]+edge[i].val);
int gf;
if(f[x][1]==g[to]+edge[i].val-max(g[to],g[to]+f[to][1]+edge[i].val))gf=f[x][2];
else gf=f[x][1];
g[to]+=max(gg,gg+gf+edge[i].val);
gf=gg+edge[i].val-max(gg,gg+gf+edge[i].val);
if(gf>f[to][1])f[to][2]=f[to][1],f[to][1]=gf;
else if(gf>f[to][2])f[to][2]=gf;
redfs(to,x);
f[to][1]=o1,f[to][2]=o2;
g[to]=w2;
}
}
{
int f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
for(int i=1;i<n;i++)
{
}