BZOJ 3391 Tree Cutting网络破坏
不想写。
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<algorithm>
- #include<cmath>
- #include<map>
- #define pa pair<int,int>
- #define inf 1000000000
- #define ll long long
- using namespace std;
- inline int read()
- {
- int x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- int n,cnt,ind,ans;
- int dfn[],low[],last[],size[];
- bool mark[];
- struct edge{int to,next;}e[];
- void insert(int u,int v)
- {
- e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
- e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
- }
- void tarjan(int x)
- {
- dfn[x]=low[x]=++ind;
- size[x]=;
- int t=,res=n-;
- for(int i=last[x];i;i=e[i].next)
- if(!dfn[e[i].to])
- {
- tarjan(e[i].to);
- size[x]+=size[e[i].to];
- low[x]=min(low[x],low[e[i].to]);
- if(low[e[i].to]>=dfn[x])
- {
- t=max(t,size[e[i].to]);
- res-=size[e[i].to];
- }
- }
- else low[x]=min(low[x],dfn[e[i].to]);
- t=max(t,res);
- if(t<=n/)
- {
- ans++;
- mark[x]=;
- }
- }
- int main()
- {
- n=read();
- for(int i=;i<n;i++)
- {
- int u=read(),v=read();
- insert(u,v);
- }
- for(int i=;i<=n;i++)if(!dfn[i])tarjan(i);
- if(!ans)puts("NONE");
- else
- for(int i=;i<=n;i++)
- if(mark[i])printf("%d\n",i);
- return ;
- }
BZOJ 3391 Tree Cutting网络破坏的更多相关文章
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏( dfs )
因为是棵树 , 所以直接 dfs 就好了... ---------------------------------------------------------------------------- ...
- 3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 76 Solved: 59[ ...
- BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 47 Solved: 37[ ...
- 【BZOJ】3391: [Usaco2004 Dec]Tree Cutting网络破坏(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=3391 显然判断每个点只需要判断子树是否小于等于n/2即可 那么我们虚拟一个根,然后计算每个子树的si ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏(树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3391 [题目大意] 给定一棵树,求分支size均不大于一半点数的点 [题解] 递归的同 ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏:dfs【无根树 节点分枝子树大小】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3391 题意: 给你一棵无根树,求分支size均不大于一半点数的点. 题解: 假定1为根. ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)
这道直接遍历一遍求出每个点的子节点数目就行了= = CODE: #include<cstdio>#include<iostream>#include<algorithm& ...
- 【树形dp】Bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
Description 约翰意识到贝茜建设网络花费了他巨额的经费,就把她解雇了.贝茜很愤怒,打算狠狠报 复.她打算破坏刚建成的约翰的网络. 约翰的网络是树形的,连接着N(1≤N≤1000 ...
- 【枚举】bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
#include<cstdio> using namespace std; #define N 10001 int n; int v[N<<1],first[N],next[N ...
随机推荐
- 在线API文档
http://www.ostools.net/apidocs A Ace akka2.0.2 Android Ant Apache CXF Apache HTTP服务器 ASM字节码操作 AutoCo ...
- C# 匿名方法 1027
class Program { static void Main(string[] args) { SorAndShowFiles("Sorted by name", delega ...
- poj 2349(最小生成树应用)
题目链接:http://poj.org/problem?id=2349 思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接 ...
- API 版本控制
http://www.oschina.net/translate/introduction-to-web-api-versioning
- C++运算符重载——重载一元运算符
0.重载一元操作符的方法 一元运算符即只需要一个操作用的运算符,如取地址运算符(&).复数(-).自减(--).自加(++)等. 运算符重载可以分为3种方式:类的非静态成员函数.类的友元函数. ...
- Tail-chaining(末尾连锁)中断说明
[转载]http://lxdawn.blog.163.com/blog/static/173620990201273111337204/ Tail-chaining是指一个中断退出至下一个中断进入这段 ...
- Linux基础--文件与目录管理
1.目录与路径 1)特殊目录 . 代表此层目录 .. 代表上一层目录 - 代表前一个工作目录 ~ 代表『目前使用者身份』所在的家目录 ~account 代表account这个使用者的 ...
- iOS开发--动画(Animation)总结
UIView的,翻转.旋转,偏移,翻页,缩放,取反的动画效果 翻转的动画 //开始动画 [UIView beginAnimations:@"doflip" context:ni ...
- jq的bind用法
type,[data],function(eventObject)String,Object,Function type: 含有一个或多个事件类型的字符串,由空格分隔多个事件.比如"clic ...
- TWinControl与TControl的覆盖函数(TWinControl对TControl的10个消息覆盖函数,17个覆盖函数,私有虚函数仍可多态)
手工找出来,对比一下,有助于VCL框架的理解.----------------------------------------------------------------------------- ...