码迷,mamicode.com
首页 > 编程语言 > 详细

HDU 5296 Annoying problem LCA+树状数组

时间:2015-07-22 21:00:45      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:

题解链接


Annoying problem

Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 480    Accepted Submission(s): 146


Problem Description
Coco has a tree, whose nodes are conveniently labeled by 1,2,…,n, which has n-1 edge,each edge has a weight. An existing set S is initially empty.
Now there are two kinds of operation:

1 x: If the node x is not in the set S, add node x to the set S
2 x: If the node x is in the set S,delete node x from the set S

Now there is a annoying problem: In order to select a set of edges from tree after each operation which makes any two nodes in set S connected. What is the minimum of the sum of the selected edges’ weight ?

 

Input
one integer number T is described in the first line represents the group number of testcases.( T<=10 ) 
For each test:
The first line has 2 integer number n,q(0<n,q<=100000) describe the number of nodes and the number of operations.
The following n-1 lines each line has 3 integer number u,v,w describe that between node u and node v has an edge weight w.(1<=u,v<=n,1<=w<=100)
The following q lines each line has 2 integer number x,y describe one operation.(x=1 or 2,1<=y<=n)


 

Output
Each testcase outputs a line of "Case #x:" , x starts from 1.
The next q line represents the answer to each operation.

 

Sample Input
1 6 5 1 2 2 1 5 2 5 6 2 2 4 2 2 3 2 1 5 1 3 1 4 1 2 2 5
 

Sample Output
Case #1: 0 6 8 8 4
 

Author
FZUACM
 

Source
 
 题意:
给定n个点的树,q个询问。
1 u,表示选中树上的点u
2 u,表示取消选中点u
对于每个询问输出:
选中的点所构成的图内的边权和是多少。

思路和代码:点击打开链接

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5296 Annoying problem LCA+树状数组

标签:

原文地址:http://blog.csdn.net/qq574857122/article/details/47008399

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!