Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <cstdio>#include <cstring>#include <algorithm>#include <cctype>#include <queue>#define rep(i, l, r) for(int i=l; i<=r; i++)#define down(i, l, r) for(int i=l; i>=r; i--)#define clr(x, c) memset(x, c, sizeof(x))#define travel(x) for(edge *p=fir[x]; p; p=p->n)#define maxn 100009#define maxm 100009#define inf 0x7fffffff#define ll long longusing namespace std;int read(){int x=0, f=1; char ch=getchar();while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}while (isdigit(ch)) x=x*10+ch-'0', ch=getchar();return x*f;}struct edge{int y; edge *n;} e[maxm], *fir[maxn], *pt=e;void AddE(int x, int y){pt->y=y, pt->n=fir[x], fir[x]=pt++;}int n, f[maxn], s[maxn], q[maxn];void dfs(int x){travel(x) dfs(p->y);int tot=0;travel(x) q[++tot]=f[p->y];sort(q+1, q+1+tot);if (tot>1) s[x]=q[tot]+q[tot-1]+2;