POJ 4045 Power Station

Description

 

The massive tsunami that struck the coastal city has  washed away many of 
inhabitants and facilities there. After the tsunami,  the power supply facilities  of  the 
coastal city  are completely destroyed. People are in panic in the dark night. Doubts 
remain over whether the communities will be able to rebuild the city. To calm people 
down, the heads of the city are planning to rebuild  the city to start with the recovery 
of the power supply facilities. 
The coastal city consists of n communities which are numbered from 1 to n. To 
save the electric cables,  n-1  cables has been used to connect these  communities 
together, so that each pair of communities  is able to transfer electronic energy 
mutually.   
The heads of the city decide to set a power station in one of the communities. 
There  is  thermal energy loss along the cables. Each cable has a resistance of R ohm. 
The total  thermal energy loss is the sum of  I^2* Ri . Here  Ri is the total residence along 
the path between the  ith community and the power station, and I is a constant. They 
are troubling their head on the issue of where to set the power station to make the total 
thermal energy loss minimized.

Input

 

There are multiple test cases. 
The first line contains one integer indicating the number of test cases. 
For each test case, the first line contains three positive integers  n,  I  and  R, 
indicating  the number of communities, the  above mentioned constant  and the 
residence of each cable. (3 ≤ n ≤ 50000, 1 ≤ I ≤ 10, 1 ≤ R ≤ 50) 
The next n-1 lines, each describe a cable connection by two integers X, Y, which 
indicates that between community X and community Y, there is a cable. 

Output

 

For each test case, please output two lines. 
The first line is the minimum total thermal energy loss. 
The second line is all the optional communities in ascending order. 
You are requested to leave a blank line after each test case. 

Sample Input

 

5 1 1 
3 2 
1 2 
5 2 
4 3 6 1 2 
1 2 
2 3 
3 4 
2 6 
3 5 

Sample Output

 

 
14 
2 3


树形dp,求出树上所有点到其他点的距离和
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int maxn=50005;
vector tree[maxn];
LL x,y,T,n,cnt[maxn],sum[maxn],f[maxn];
LL I,R;

void dfs(int x,int fa)
{
	cnt[x]=1;	sum[x]=0;
	for (int i=0;i


你可能感兴趣的:(POJ,----树形dp)