2014多校5(1002)hdu4912(贪心+LCA)
来源:互联网 发布:免费手机记账软件 编辑:程序博客网 时间:2024/05/17 23:34
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.
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).
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.
A single integer, the maximum number of paths.
Sample Input
3 21 21 31 21 37 31 21 32 42 53 63 72 34 56 7
Sample Output
12
题意:给出了m条路径,需要你选择尽量多的路径使得两两之间没有公共点
思路:以任意一点为根dfs树,然后优先选择路径中最小深度的节点(可以用LCA求)最深的路径,每次选完一条路径以后将该路径中以最小深度节点为根的子树标记(之后不能再选),然后就没了。
0 0
- 2014多校5(1002)hdu4912(贪心+LCA)
- 2014多校5---1002 HDU4912 ( Paths on the tree ) LCA+贪心+bfs/dfs
- hdu4912 LCA+贪心
- hdu4912 贪心+lca
- hdu4912 Paths on the tree --- LCA贪心
- HDU4912 Paths on the tree(数据结构,lca,贪心)
- hdu4912
- HDU4912
- HDU 4912 lca贪心
- HDU4912注解
- HDU 4912 - Paths on the tree (LCA 贪心)
- HDU 4912 Paths on the tree (LCA+贪心)
- HDU 4912 Paths on the tree(LCA+贪心)
- [BZOJ4568][Scoi2016]幸运数字(高斯消元求线性基+lca+贪心)
- CF 593D LCA,贪心
- HDU 5773 The All-purpose Zero 16多校4 贪心 LCA
- HDU 6203 ping ACM/ICPC 2017 Shenyang Online(LCA+贪心)
- [NOIP] [LCA] [贪心] NOIP2012Day2 疫情控制(blockade)
- GPIO及中断API函数
- JDBC链接数据库及使用代码
- Java 排序之 插入排序
- 从TXT文本文档向Sql Server中批量导入数据
- 【实践驱动开发3-005】TI WL1835MODCOM8 在android的移植 - SDIO and wifi 基础
- 2014多校5(1002)hdu4912(贪心+LCA)
- UIWebView 相关
- 03.pull解析xml
- Network 20Q--Q2 How does Google sell ad spaces?
- Controller通过@RequestBody接收参数
- SD3.0协议解读四
- Xenomai thread migration
- Cocos2d3.0话说ValueMap的一般用法
- Android的一些小东西和工具