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 ...
随机推荐
- HDU 4597 Play Game(记忆化搜索,深搜)
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...
- sql server 数据库 数据DateTime 转mysql
首先将sql server DateTime 转换为varchar(50) 然后更新转换过的 DateTime字段, UPDATE 表名 SET LastUpdateTime=CONVERT(VAR ...
- 数据库中已存在名为 'View_Business' 的对象。
用EF框架+MCF,编译的时候出现:数据库中已存在名为 'View_Business' 的对象. 解决方案: 1.Enable-Migrations2.Add-Migration3.Update-Da ...
- Good Bye 2015 A. New Year and Days 签到
A. New Year and Days Today is Wednesday, the third day of the week. What's more interesting is tha ...
- 如何向AcmeAir注入问题代码
为什么要注入问题代码? AcmeAir的常规代码是为了压测测试准备的,所以绝大部分的操作都是可以在几十毫秒中就可以正常返回的.为了向用户展示我们APM工具可以在源代码级别发现系统潜在问题,我们需要在A ...
- 【总结】java命令解析以及编译器,虚拟机如何定位类
学Java有些日子了,一直都使用IDE来写程序.这样的好处就是能让我连如何用命令行编译,解释执行Java源代码都不知道,就更不清楚JDK中的编译器和虚拟机(包含字节码解释器)是如何定位到类文件的.悲哀 ...
- 285. Inorder Successor in BST
题目: Given a binary search tree and a node in it, find the in-order successor of that node in the BST ...
- java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener ----good
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListe ...
- Java中使用验证码和二维码
资源 需要: jelly-core-1.7.0.GA.jar 网站: http://lychie.github.io/products.html 将下载下来的 jelly-core-1.7.0 ...
- ColorDescriptor software v4.0 一个提取颜色特征描述子的软件包
ColorDescriptor software v4.0 Created by Koen van de Sande, (c) University of Amsterdam Note: Any co ...