2014多校5(1002)hdu4912(贪心+LCA)
2014-08-06 16:53
302 查看
Paths on the tree
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 424 Accepted Submission(s): 127
Problem Description
bobo has a tree, whose vertices are conveniently labeled by 1,2,…,n.
There are m paths on the tree. bobo would like to pick some paths while any two paths do not share common vertices.
Find the maximum number of paths bobo can pick.
Input
The input consists of several tests. For each tests:
The first line contains n,m (1≤n,m≤105). Each of the following (n - 1) lines contain 2 integers ai,bi denoting an edge between vertices ai and bi (1≤ai,bi≤n). Each of the following
m lines contain 2 integers ui,vi denoting a path between vertices ui and vi (1≤ui,vi≤n).
Output
For each tests:
A single integer, the maximum number of paths.
Sample Input
3 2 1 2 1 3 1 2 1 3 7 3 1 2 1 3 2 4 2 5 3 6 3 7 2 3 4 5 6 7
Sample Output
1 2
题意:给出了m条路径,需要你选择尽量多的路径使得两两之间没有公共点
思路:以任意一点为根dfs树,然后优先选择路径中最小深度的节点(可以用LCA求)最深的路径,每次选完一条路径以后将该路径中以最小深度节点为根的子树标记(之后不能再选),然后就没了。
相关文章推荐
- HDU_4912 Path on the tree 2014多校5 贪心+LCA
- 2014多校第十场1002 || HDU 4972 A simple dynamic programming problem
- hdu 4888 2014多校第三场1002 Redraw Beautiful Drawings 网络流
- [贪心+DFS序列维护树上前缀和]2014 Multi-University Training Contest 5 - 1002 Paths on the tree
- 2014多校3(1002)hdu4888(最大流(dinic))
- hdu4912 Paths on the tree --- LCA贪心
- 2016 多校4 1002 After a Sleepless Night 树上贪心
- 2014多校联合第一场 1002 Jump
- HDU 4864 Task(2014多校--贪心)
- HDU 4864 Task (2014多校联合训练第一场1004) 解题报告(贪心)
- HDU 4882 ZCC Loves Codefires(2014多校第二场1011)(贪心)
- HDU 4888 Redraw Beautiful Drawings (2014-多校3-1002,最大流,判最大流有多解)
- hdu5289||2015多校联合第一场1002贪心+RMQ
- hdu4912 LCA+贪心
- 多校联合2-1002 贪心
- 2014多校联盟 第一场 Task 贪心
- HDU 4864 Task(2014多校第一场1004)(贪心)
- hdu4912 贪心+lca
- hdu4882ZCC Loves Codefires【贪心】2014多校联合
- HDU 4862 Jump (2014-多校1-1002,最小K路径覆盖,最小费用最大流)