# [BZOJ1060] [ZJOI2007]时态同步

## Description

小Q在电子工艺实习课上学习焊接电路板。一块电路板由若干个元件组成，我们不妨称之为节点，并将其用数

## Input

第一行包含一个正整数N，表示电路板中节点的个数。第二行包含一个整数S，为该电路板的激发器的编号。接

## Output

仅包含一个整数V，为小Q最少使用的道具次数

3
1
1 2 1
1 3 3

2

## HINT

N ≤ 500000，te ≤ 1000000

#include <iostream>
#include <cstdio>
using namespace std;
#define reg register
#define int long long
int res = 0;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) res=(res<<3)+(res<<1)+(ch^48), ch=getchar();
return res;
}
#define N 500005
int n, S;
struct edge {
int nxt, to, val;
}ed[N*2];
int deg[N];
inline void add(int x, int y, int z)
{
deg[y] ++;
}
int f[N], g[N];
int dis[N];

void dfs(int x, int fa, int d)
{
dis[x] = d;
for (reg int i = head[x] ; i ; i = ed[i].nxt)
{
int to = ed[i].to;
if (to == fa) continue;
dfs(to, x, d + ed[i].val);
}
}

void dp(int x, int fa)
{
if (deg[x] == 1) g[x] = dis[x];
for (reg int i = head[x] ; i ; i = ed[i].nxt)
{
int to = ed[i].to;
if (to == fa) continue;
dp(to, x);
g[x] = max(g[x], g[to]);
}
for (reg int i = head[x] ; i ; i = ed[i].nxt)
{
int to = ed[i].to;
if (to == fa) continue;
f[x] += f[to] + g[x] - g[to];
g[to] = g[x];
}
}

signed main()
{
for (reg int i = 1 ; i < n ; i ++)
{
}