Ciel the Commander CodeForces - 321C (树, 思维)
大意: 给定n结点树, 求构造一种染色方案, 使得每个点颜色在[A,Z], 且端点同色的链中至少存在一点颜色大于端点 (A为最大颜色)
直接点分治即可, 因为最坏可以涂$2^{26}-1$个节点, 所以方案一定存在
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
using namespace std;
typedef long long ll; const int N = 4e5+10, INF = 0x3f3f3f3f;
int n, sum, rt;
int mx[N], sz[N], vis[N];
vector<int> g[N];
char buf[N]; void getrt(int x, int fa) {
mx[x]=0, sz[x]=1;
for (int y:g[x]) if (!vis[y]&&y!=fa) {
getrt(y,x),sz[x]+=sz[y];
mx[x]=max(mx[x],sz[y]);
}
mx[x]=max(mx[x],sum-sz[x]);
if (mx[x]<mx[rt]) rt=x;
} void solve(int x, char c) {
vis[x]=1, buf[x]=c;
for (int y:g[x]) if (!vis[y]) {
mx[rt=0]=n,sum=sz[y];
getrt(y,0),solve(rt,c+1);
}
} int main() {
scanf("%d", &n);
REP(i,2,n) {
int u, v;
scanf("%d%d", &u, &v);
g[u].pb(v), g[v].pb(u);
}
sum=mx[0]=n,getrt(1,0),solve(rt,'A');
REP(i,1,n) printf("%c ", buf[i]);
puts("");
}
Ciel the Commander CodeForces - 321C (树, 思维)的更多相关文章
- CodeForces 321C Ciel the Commander
Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- Codeforces G. Ciel the Commander
题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治
E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest ...
- CF 322E - Ciel the Commander 树的点分治
树链剖分可以看成是树的边分治,什么是点分治呢? CF322E - Ciel the Commander 题目:给出一棵树,对于每个节点有一个等级(A-Z,A最高),如果两个不同的节点有相同等级的父节点 ...
- Codeforce 322E Ciel the Commander (点分治)
E. Ciel the Commander Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, ...
- Water Tree CodeForces 343D 树链剖分+线段树
Water Tree CodeForces 343D 树链剖分+线段树 题意 给定一棵n个n-1条边的树,起初所有节点权值为0. 然后m个操作, 1 x:把x为根的子树的点的权值修改为1: 2 x:把 ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
- codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)
题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...
- codeforces 626 G. Raffles(线段树+思维+贪心)
题目链接:http://codeforces.com/contest/626/problem/G 题解:这题很明显买彩票肯定要买贡献最大的也就是说买p[i]*(num[i]+1)/(num[i]+a[ ...
随机推荐
- linux常用命令:find命令之xargs
在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...
- seo标题关键字描述字数限制Title,keywords,description长度最长多长 ?
seo标题关键字描述字数限制 seo优化各个搜索引擎收录Title,keywords,description长度最长多长 ?SEO网站优化中Title标签的作用为重中之重,好的Title也就成功了一半 ...
- 学写网页 #04# w3school
索引: HTML 输入类型 XHTML HTML5 HTML5 样式指南和代码约定 WHO 成立于 1948 年. 对缩写进行标记能够为浏览器.翻译系统以及搜索引擎提供有用的信息. code 元素不保 ...
- Spring IOC 源码分析
Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 Spring 呢?阅读本文 ...
- Python3.x与Python2.x的差异用法
Python3.x与Python2.x的差异用法 1,关于urllib2区别: # python2 import urllib2 # python3 # 用urllib.request代替urllib ...
- 20145220韩旭飞《网络对抗》Exp2 后门原理与实践
20145220韩旭飞<网络对抗>Exp2 后门原理与实践 常用后门工具实践 Windows获得Linux Shell 在Windows下,先使用ipconfig指令查看本机IP: 使用n ...
- vim 开启我们的Python之旅
1.在我们的Mac系统下打开“终端”,输入python,然后回车即可看到我们电脑是否安装了python,以及它的版本,这里我的是2.7.5版本,如果未安装请百度之.
- win10中mount和unmount iso文件
https://www.windowscentral.com/how-mount-or-unmount-iso-images-windows-10 You can also right-click t ...
- 如何设置datatable的宽度
本文为博主原创,未经允许不得转载: datatable插件具有很好的自动适应性,在大多数情况下可以自适应,完美的展示列表内容. 实现其自适应的其特性为:"bAutoWidth": ...
- 【Coursera】SecondWeek(2)
The First Two Packets on the Internet Leonard Kleinrock Kleinrock 是一名工程师和计算机科学家,他在APRANET网络中起到了至关重要的 ...