Andryusha and Colored Balloons
来源:互联网 发布:淘宝店培训班 编辑:程序博客网 时间:2024/05/16 19:11
dfs记录一下父节点就好了
#include<iostream> #include<cstdio>#include<cstring>#include<vector>using namespace std;int arr[200004];vector<int>u[200004];int m=0;void dfs(int node ,int father){ int now=1; for(int e=0;e<u[node].size();e++) { int k=u[node][e]; if(arr[k]==-1) { while(now==arr[father]||now==arr[node]) now++; arr[k]=now++; m=max(m,now-1); dfs(k,node,father); } }}int main(){ memset(arr,-1,sizeof(arr)); int num; cin>>num; for(int i=0;i<num-1;i++) { int a,b; scanf("%d%d",&a,&b); u[a].push_back(b); u[b].push_back(a); } arr[1]=1; arr[0]=1; dfs(1,0); cout<<m<<endl; for(int i=1;i<=num;i++) { if(i!=1)cout<<" "<<arr[i]; else cout<<arr[i]; } return 0;}
0 0
- Andryusha and Colored Balloons
- codeforces781A Andryusha and Colored Balloons
- Codeforces Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons
- 【codeforces 782C】Andryusha and Colored Balloons
- codeforces 782c Andryusha and Colored Balloons
- Codeforces 780C-Andryusha and Colored Balloons
- cf 782c Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons--bfs
- 781A. Andryusha and Colored Balloons
- Codeforces Round #403 (Div. 2) C. Andryusha and Colored Balloons
- Codeforces 782C Andryusha and Colored Balloons dfs
- Codeforces Round #403 C. Andryusha and Colored Balloons(DFS)
- 【Codeforces Round #403】Codeforces 781A Andryusha and Colored Balloons
- codeforces 781A Andryusha and Colored Balloons(树上dfs)
- Codeforces Round #403 div2 C. Andryusha and Colored Balloons
- AngularJS 监听 动态增加的控件模型
- Web前端-html页面-网易注册表单,美化及时验证效果
- 接口与抽象类的区别
- jQuery实现列表内容的动态载入特效
- 二进制中正负数表示和判断
- Andryusha and Colored Balloons
- ProxyCommand
- CSS中定位的学习
- 关于sql优化的一点见解
- sdutacm-数据结构实验之栈四:括号匹配
- int与Integer的区别
- Servlet 生命周期、工作原理
- 黑马学习笔记--JAVA基础知识
- 图的遍历和图不连通怎么办