博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5452 Minimum Cut 树形dp
阅读量:4840 次
发布时间:2019-06-11

本文共 2350 字,大约阅读时间需要 7 分钟。

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 spanning tree of G.

We say that a cut in G respects T if it cuts just one edges of T.

Since love needs good faith and hypocrisy return for only grief, you should find the minimum cut of graph G respecting the given spanning tree T.

Input

The input contains several test cases.

The first line of the input is a single integer t (1≤t≤5) which is the number of test cases.
Then t test cases follow.

Each test case contains several lines.

The first line contains two integers n (2≤n≤20000) and m (n−1≤m≤200000).
The following n−1 lines describe the spanning tree T and each of them contains two integers u and v corresponding to an edge.
Next m−n+1 lines describe the undirected graph G and each of them contains two integers u and v corresponding to an edge which is not in the spanning tree T.

Output

For each test case, you should output the minimum cut of graph G respecting the given spanning tree T.

Sample Input

1 4 5 1 2 2 3 3 4 1 3 1 4

Sample Output

Case #1: 2

HINT

 

题意

给你一个没有自环重边的无向图,然后给你一颗生成树,让你求一个最小割集的大小,使得这个割集有且只有一条边在这棵生成树上

题解:

树形dp,对于这个点,如果要消除他和他父亲之间的联系的话,代价就是他的子树所有连向外界的边就好了

跑一遍dfs维护一下就行了

-------------------------

我的方法是错的,已经被hack了

数据:

 2
4 4 1 2 2 3 3 4 1 3
4 4 1 3 2 3 2 4 1 2 

代码:

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 20050#define mod 10007#define eps 1e-9int Num;char CH[20];//const int inf=0x7fffffff; //нчоч╢Сconst int inf=0x3f3f3f3f;//*********************************************************************************vector
Q[maxn];vector
E[maxn];int vis[maxn];int dp[maxn];int ans;void dfs(int x){ vis[x]=1; for(int i=0;i
y)swap(x,y); Q[x].push_back(y); } for(int i=n-1;i
y)swap(x,y); E[y].push_back(x); } dfs(1); printf("Case #%d: %d\n",cas,ans); }}

 

转载于:https://www.cnblogs.com/qscqesze/p/4822468.html

你可能感兴趣的文章
hdu 5452 Minimum Cut 树形dp
查看>>
perf4j @Profiled常用写法
查看>>
配置的热更新
查看>>
ios view的frame和bounds之区别(位置和大小)
查看>>
USB小白学习之路(11) Cy7c68013A驱动电路设计注意事项(转)
查看>>
Luogu 2530 化工厂装箱员
查看>>
自定义webUI实例
查看>>
用NSAttributedString实现简单的图文混排
查看>>
多语境的操作
查看>>
SNS营销——网商成功之道
查看>>
jqgrid 加载时第一页面只显示多少条数据
查看>>
magic模块 :Exception Value:failed to find libmagic. Check your installation
查看>>
C#小游戏(文字对战游戏)
查看>>
COGS2314. [HZOI 2015] Persistable Editor
查看>>
my college goal
查看>>
java switch case 枚举类型的反编译结果
查看>>
关于dubbo+shiro导致dubbo无法注入到Realm的问题解决方案
查看>>
entity framework使用技巧
查看>>
面试题24: 反转链表
查看>>
Ubuntu 下安装 Oracle Java
查看>>