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

The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if ab and c are distinct squares that a and b have a direct path between them, and b and c have a direct path between them, then balloon colors on these three squares are distinct.

Andryusha wants to use as little different colors as possible. Help him to choose the colors!

Input

The first line contains single integer n (3 ≤ n ≤ 2·105) — the number of squares in the park.

Each of the next (n - 1) lines contains two integers x and y (1 ≤ x, y ≤ n) — the indices of two squares directly connected by a path.

It is guaranteed that any square is reachable from any other using the paths.

Output

In the first line print single integer k — the minimum number of colors Andryusha has to use.

In the second line print n integers, the i-th of them should be equal to the balloon color on the i-th square. Each of these numbers should be within range from 1 to k.

Examples

Input
3
2 3
1 3
Output
3
1 3 2
Input
5
2 3
5 3
4 3
1 3
Output
5
1 3 2 5 4
Input
5
2 1
3 2
4 3
5 4
Output
3
1 2 3 1 2

Note

In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.

 Illustration for the first sample.

In the second example there are following triples of consequently connected squares:

  • 1 → 3 → 2
  • 1 → 3 → 4
  • 1 → 3 → 5
  • 2 → 3 → 4
  • 2 → 3 → 5
  • 4 → 3 → 5

We can see that each pair of squares is encountered in some triple, so all colors have to be distinct.

 Illustration for the second sample.

In the third example there are following triples:

  • 1 → 2 → 3
  • 2 → 3 → 4
  • 3 → 4 → 5

We can see that one or two colors is not enough, but there is an answer that uses three colors only. Illustration for the third sample.

题意:给出n个节点,让你给这棵树染色,要求用的颜色最少,然后要求任意三个相连的颜色不能相同___________________________________________________________________________________思路:最原始的染色是黑白染色,只要求相邻不相同就行,而这个要求三个相连不相同,其实我们只要保存前两个节点颜色是什么,然后再去找即可,有一个要理解的地方,就是由两个节点推导过来的颜色,那个点相邻的几个节点肯定颜色都是不同的,如图

从上图中可以看到这是错误的,说明由两点推出来的点肯定都不一样,所以上图那三点应该分别染色 3,4,5,详细见代码

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
vector<int> mp[];
int n,x,y;
int vis[];
void dfs(int x,int y)
{
int cnt=;//上面已解释
for(int i=;i<mp[x].size();i++)
{
if(mp[x][i]==y) continue;
while(cnt==vis[x]||cnt==vis[y])//寻找可以赋值的颜色
cnt++;
vis[mp[x][i]]=cnt++;//给节点染色
}
for(int i=;i<mp[x].size();i++)//使用新的两个节点
{
if(mp[x][i]!=y)
dfs(mp[x][i],x);
}
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n-;i++)//领接表建图
{
scanf("%d%d",&x,&y);
mp[x].push_back(y);
mp[y].push_back(x);
}
vis[]=;
dfs(,);
int mx=vis[];
for(int i=;i<=n;i++)//取最大颜色
mx=max(mx,vis[i]);
printf("%d\n",mx);
for(int i=;i<=n;i++)
{
printf("%d ",vis[i]);
}
}

最新文章

  1. ASP.NET Core 在 JSON 文件中配置依赖注入
  2. Lind.DDD.Caching分布式数据集缓存介绍
  3. TABLE CONTROL隐藏列和固定列的实现
  4. 【poj1419】 Graph Coloring
  5. Android课程---Android Studio使用小技巧:提取方法代码片段
  6. 列出当前ARM开发板系统加载的模块
  7. Openstack之Swift架构(Cloud Storage)
  8. Windows下使用Visual Studio 2010编译ffmpeg全过程
  9. 线索二叉树Threaded binary tree
  10. UART接口
  11. Linux watch 命令
  12. C语言模拟实现多态
  13. Jetty添加Filter过滤器
  14. NOIP 2015运输计划
  15. CH 3101 - 阶乘分解 - [埃筛]
  16. 【转】java面试题
  17. html介绍和head标签
  18. [JavaScript] Nginx实现跨域设置
  19. &quot;添加&quot;模态框中某些数据不被清空
  20. 第三百七十八节,Django+Xadmin打造上线标准的在线教育平台—django自带的admin后台管理介绍

热门文章

  1. java 循环读取文件夹里面的文件
  2. ubuntu opencv
  3. PHP const关键字
  4. Dynamic Shortest Path CodeForces - 843D (动态最短路)
  5. 论raw_input与input之间的缠缠绵绵
  6. C++的成员初始化列表和构造函数体(以前未知)
  7. ayit-#41. 因数的个数-数论
  8. Leetcode 1012. 十进制整数的反码
  9. [CodeForces - 614D] D - Skills
  10. CURD插件(仿Django-admin版)