hdu 4612 (双联通+树形DP)】的更多相关文章

加一条边后最少还有多少个桥,先Tarjan双联通缩点, 然后建树,求出树的直径,在直径起点终点加一条边去的桥最多, #pragma comment(linker, "/STACK:1024000000,1024000000") #include<stdio.h> #include<string.h> #include<stack> #define N 200001 using namespace std; int belong[N],head[N],…
#pragma comment(linker,"/STACK:102400000,102400000")//总是爆栈加上这个就么么哒了 #include<stdio.h> #include<queue> #include<string.h> using namespace std; #define N 210000 #define inf 99999999 struct node { int u,v,w,next; }bian[N*20],biant…
/*先求出双联通缩点,然后进行树形dp*/ #include<stdio.h> #include<string.h> #include<math.h> #define inf 0x3fffffff #define N 11000 struct node { int u,v,next; } bian[N*4],edge[N*4]; int head[N],yong,dfn[N],low[N],index,f[N*4],cnt,n,num[N]; int yon; int…
Warm up Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 3160    Accepted Submission(s): 718 Problem Description N planets are connected by M bidirectional channels that allow instant transport…
Information Disturbing Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 3205    Accepted Submission(s): 1137 Problem Description In the battlefield , an effective way to defeat enemies is to bre…
<题目链接> 题目大意: 给定一个连通图,每个点有点权,现在需要删除一条边,使得整张图分成两个连通块,问你删除这条边后,两联通块点权值和差值最小是多少. 解题分析: 删除一条边,使原连通图分成两个连通分量,所以删除的那条边必然是桥.为了得到所有的桥,我们对原图进行边双连通图缩点.然后对缩点后的新图,跑一遍树形DP,得到所有桥两端点权和的最小差值. #include <bits/stdc++.h> using namespace std; #define clr(a,b) memse…
一个公司的职员是分级制度的,所有员工刚好是一个树形结构,现在公司要举办一个聚会,邀请部分职员来参加. 要求: 1.为了聚会有趣,若邀请了一个职员,则该职员的直接上级(即父节点)和直接下级(即儿子节点)都不能被邀请 2.每一个员工都有一个兴奋值,在满足1的条件下,要使得邀请来的员工的兴奋值最高 输出最高的兴奋值. 简单的树形DP dp[i][1]:表示以i为根的子树,邀请节点i的最大兴奋值 dp[i][0]:表示以i为根的子树,不邀请节点i的最大兴奋值 先根据入度找出整棵树的根节点, 然后一次DF…
Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5452 Description Given a simple unweighted graph G (an undirected graph containing no loops nor multiple edges) with n nodes and m edges. Let T be a spa…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 题目大意:给出n个带权点,他们的关系可以构成一棵树,问从中选出若干个不相邻的点可能得到的最大值为多少 解题思路:简单的树形DP 用dp[i][0]表示以i为根的树上不取i的状态下能得到的最大值 用dp[i][1]表示以i为根的树取i的状态下能得到的最大值 状态转移方程 dp[i][0]=∑(max(dp[son(i)][0],dp[son(i)][1])) dp[i][1]=∑(dp[son(…
Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4310    Accepted Submission(s): 1976 Problem Description There is going to be a party to celebrate the 80-th Anniversary of the…