这种问题的转化方式挺巧妙的. Code: #include <bits/stdc++.h> #define N 100000 #define M 1000000 #define setIO(s) freopen(s".in","r",stdin) using namespace std; queue<int>q; vector<int>G,V[N]; int n,root,edges; int fa[20][N],hd[N],to…
BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among the vertices, of them are red, while the others are black. The root of the tree is vertex 1 and it's a red vertex.Let's define the cost of a red verte…