C - Andryusha and Colored Balloons

思路:

  水题;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 200005 int n,head[maxn],cnt,E[maxn<<],V[maxn<<],dis[maxn],ans; void dfs(int now,int fa)
{
int ki=;
for(int i=head[now];i;i=E[i])
{
if(V[i]==fa) continue;
ki++;
if(ki==dis[fa]) ki++;
if(ki==dis[now]) ki++;
if(ki==dis[fa]) ki++;
if(ki==dis[now]) ki++;
dis[V[i]]=ki,dfs(V[i],now);
}
} int main()
{
scanf("%d",&n);int u,v;
for(int i=;i<n;i++)
{
scanf("%d%d",&u,&v);
E[++cnt]=head[u],V[cnt]=v,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,head[v]=cnt;
}
dis[]=,dfs(,);
for(int i=;i<=n;i++) ans=max(ans,dis[i]);
printf("%d\n",ans);
for(int i=;i<=n;i++) printf("%d ",dis[i]);
return ;
}

AC日记——Andryusha and Colored Balloons codeforces 780c的更多相关文章

  1. Codeforces 782C. Andryusha and Colored Balloons 搜索

    C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...

  2. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C Andryusha and Colored Balloons

    地址:http://codeforces.com/contest/782/problem/C 题目: C. Andryusha and Colored Balloons time limit per ...

  3. code force 403C.C. Andryusha and Colored Balloons

    C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes ...

  4. codeforces781A Andryusha and Colored Balloons

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  5. C. Andryusha and Colored Balloons

    C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. CodeForces - 780C Andryusha and Colored Balloons(dfs染色)

    Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, ...

  7. AC日记——Andryusha and Socks Codeforces 780a

    A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. 【codeforces 782C】Andryusha and Colored Balloons

    [题目链接]:http://codeforces.com/contest/782/problem/C [题意] 给你一棵树 让你满足要求 ->任意相连的3个节点的颜色不能相同 的情况下进行染色 ...

  9. Codeforces 781A:Andryusha and Colored Balloons(DFS染色)

    http://codeforces.com/contest/782/problem/C 题意:给一棵树染最少的颜色,使得相邻距离为2的点都是不同的颜色,问最少是多少种颜色并输出每个点的颜色. 思路:比 ...

随机推荐

  1. linux之shell脚本学习篇一

    此文包含脚本服务请求,字符串截取,文件读写内容,打印内容换行. #!/bin/bashretMsg="";while read LINEdo        echo "t ...

  2. media="screen"是什么意思?

    <link rel="stylesheet" href="css/main.css" type="text/css" media=&q ...

  3. [HAOI2010]计数

    题面在这里 description 你有一组非零数字(不一定唯一),你可以在其中插入任意个0,这样就可以产生无限个数. 比如说给定{1,2},那么可以生成数字12,21,102,120,201,210 ...

  4. Android逆向之旅---静态方式分析破解视频编辑应用「Vue」水印问题

    一.故事背景 现在很多人都喜欢玩文艺,特别是我身边的UI们,拍照一分钟修图半小时.就是为了能够在朋友圈显得逼格高,不过的确是挺好看的,修图的软件太多了就不多说了,而且一般都没有水印啥的.相比较短视频有 ...

  5. 线程 packaged_task future

    http://www.cnblogs.com/haippy/p/3279565.html #include <iostream> // std::cout #include <fut ...

  6. TSP问题之状压dp法

    首先,我们先来认识一下什么叫做TSP问题 旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题.货郎担问题,是数学领域中著名问题之一.假设有一个旅行商人 ...

  7. 笔记本电脑上面安装linux网络配置以及ping通问题

    ping不同,XShell连接不上linux: 360全部关闭,即可. 具体参考: http://blog.csdn.net/xiezhaoxuan/article/details/52673236 ...

  8. 使用mysqldump命令备份恢复MySQL数据库

    1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump file] 上述命令将指定数据库备份到某dump文 ...

  9. C# 序列化原因 (转)

         1.什么是序列化 序列化是将对象状态转换为可保持或传输的格式的过程,在序列化过程中,对象的公共字段和私有字段以及类的名称(包括包含该类的程序集)都被转换为字节流,然后写入数据流.与序列化相对 ...

  10. c语言指针学习【转】

    前言 近期俄罗斯的陨石.四月的血月.五月北京的飞雪以及天朝各种血腥和混乱,给人一种不详的预感.佛祖说的末法时期,五浊恶世 ,十恶之世,人再无心法约束,道德沦丧,和现在正好吻合.尤其是在天朝,空气,水, ...