#P9194. [USACO23OPEN] Triples of Cows P

[USACO23OPEN] Triples of Cows P

题目描述

There are initially N1N-1 pairs of friends among FJ's NN cows labeled 1N1\dots N, forming a tree. The cows are leaving the farm for vacation one by one. On day ii, the ii th cow leaves the farm, and then all pairs of the ii th cow's friends still present on the farm become friends.

For each ii from 11 to NN, just before the ii th cow leaves, how many ordered triples of distinct cows (a,b,c)(a,b,c) are there such that none of a,b,ca,b,c are on vacation, aa is friends with bb, and bb is friends with cc?

输入格式

The first line contains NN.

The next N1N-1 lines contain two integers uiu_i and viv_i denoting that cows uiu_i and viv_i are initially friends.

输出格式

The answers for ii from 11 to NN on separate lines.

题目大意

给定一棵初始有 nn 个点的树。

在第 ii 天,这棵树的第 ii 个点会被删除,所有与点 ii 直接相连的点之间都会两两连上一条边。你需要在每次删点发生前,求出满足 (a,b)(a,b) 之间有边,(b,c)(b,c) 之间有边且 aca\not=c有序三元组 (a,b,c)(a,b,c) 对数。

3
1 2
2 3

2
0
0

4
1 2
1 3
1 4

6
6
0
0

5
3 5
5 1
1 4
1 2

8
10
2
0
0

提示

For the first sample:
(1,2,3)(1,2,3) and (3,2,1)(3,2,1) are the triples just before cow 11 leaves.
After cow 11 leaves, there are less than 33 cows left, so no triples are possible.

For the second sample:
At the beginning, cow 11 is friends with all other cows, and no other pairs of cows are friends, so the triples are (a,1,c)(a, 1, c) where a,ca, c are different cows from {2,3,4}\{2, 3, 4\}, which gives 32=63 \cdot 2 = 6 triples.
After cow 11 leaves, the remaining three cows are all friends, so the triples are just those three cows in any of the 3!=63! = 6 possible orders.
After cow 22 leaves, there are less than 33 cows left, so no triples are possible.

2N21052\le N\le 2\cdot 10^5, 1ui,viN1\le u_i,v_i\le N.

  • Inputs 4-5: N500N\le 500.
  • Inputs 6-10: N5000N\le 5000.
  • Inputs 11-20: No additional constraints.