logo AlgoBeat OnlineJudge
登录 注册

#208585. [USACO23OPEN] Triples of Cows P

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

For each from to , just before the th cow leaves, how many ordered triples of distinct cows are there such that none of are on vacation, is friends with , and is friends with ?

输入格式

The first line contains .

The next lines contain two integers and denoting that cows and are initially friends.

输出格式

The answers for from to on separate lines.

样例

样例输入 1

3
1 2
2 3

样例输出 1

2
0
0

样例输入 2

4
1 2
1 3
1 4

样例输出 2

6
6
0
0

样例输入 3

5
3 5
5 1
1 4
1 2

样例输出 3

8
10
2
0
0

数据范围与提示

For the first sample:
and are the triples just before cow leaves.
After cow leaves, there are less than cows left, so no triples are possible.

For the second sample:
At the beginning, cow is friends with all other cows, and no other pairs of cows are friends, so the triples are where are different cows from , which gives triples.
After cow leaves, the remaining three cows are all friends, so the triples are just those three cows in any of the possible orders.
After cow leaves, there are less than cows left, so no triples are possible.

, .

  • Inputs 4-5: .
  • Inputs 6-10: .
  • Inputs 11-20: No additional constraints.