博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【bzoj1086】 scoi2005—王室联邦
阅读量:4337 次
发布时间:2019-06-07

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

 (题目链接)

题意

  求将树分为几个联通块,每个联通块大小大于B小于3B,是否可行。

Solution

  题都没看就翻了题解。。

代码

// bzoj3757#include
#include
#include
#include
#include
#include
#define MOD 1000000007#define inf 2147483640#define LL long long#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);using namespace std;inline LL getint() { LL x=0,f=1;char ch=getchar(); while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();} while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();} return x*f;}const int maxn=1010;struct edge {int next,to;}e[maxn<<2];int head[maxn],size[maxn],pos[maxn],q[maxn],n,B,cnt,top,c,cap[maxn];void insert(int u,int v) { e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt; e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt;}void dfs(int x,int fa) { q[++top]=x; for (int i=head[x];i;i=e[i].next) if (e[i].to!=fa) { dfs(e[i].to,x); if (size[x]+size[e[i].to]>=B) { size[x]=0; cap[++cnt]=x; while (q[top]!=x) pos[q[top--]]=cnt; } else size[x]+=size[e[i].to]; } size[x]++;}void paint(int x,int fa,int c) { if (pos[x]) c=pos[x]; else pos[x]=c; for (int i=head[x];i;i=e[i].next) if (e[i].to!=fa) paint(e[i].to,x,c);}int main() { scanf("%d%d",&n,&B); for (int i=1;i

  

转载于:https://www.cnblogs.com/MashiroSky/p/5914607.html

你可能感兴趣的文章
RocketMQ配置
查看>>
蚂蚁金服井贤栋:用技术联手金融机构,形成服务小微的生态合力
查看>>
端口号大全
查看>>
机器学习基石笔记2——在何时可以使用机器学习(2)
查看>>
POJ 3740 Easy Finding (DLX模板)
查看>>
MySQL 处理重复数据
查看>>
关于typedef的用法总结(转)
查看>>
【strtok()】——分割字符串
查看>>
Linux下安装rabbitmq
查看>>
曹德旺
查看>>
【转】判断点在多边形内(matlab)
查看>>
java基础之集合:List Set Map的概述以及使用场景
查看>>
Python 线程 进程 协程
查看>>
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>