Triples of Cows
시간 제한: 2000ms메모리 제한: 1024MB출처: USACO 2023 Open PlatinumBOJ 28027
문제
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
출력
2 0 0
예제 2
입력
4 1 2 1 3 1 4
출력
6 6 0 0
예제 3
입력
5 3 5 5 1 1 4 1 2
출력
8 10 2 0 0
코드를 제출하려면 로그인하세요.