Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals
来源:互联网 发布:男朋友礼物 知乎 编辑:程序博客网 时间:2024/06/06 00:19
C题思路:生成树上的dfs,完全没见过,留作复习
代码:
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>#include<queue>#include<string>#include<vector>#define maxn 210000using namespace std;int n;vector<int>aaa[maxn];int power[maxn];int color[maxn];void dfs(int x, int fa) {//对第x个节点的子节点们开始染色,x的父节点是fAint c = 1;for (int i = 0; i < aaa[x].size(); i++) {int temp = aaa[x][i];if (color[temp] != 0)continue;while (c == color[x] || c == color[fa])c++;color[temp] = c;dfs(temp, x);c++;}}int ans;int main() {memset(color, 0, sizeof(color));memset(power, 0, sizeof(power));ans = 0;scanf("%d", &n);int a, b;for (int i = 1; i < n; i++) {scanf("%d %d", &a, &b);power[a]++; power[b]++;ans = max(ans, max(power[a], power[b]));aaa[a].push_back(b);aaa[b].push_back(a);}ans++;cout << ans << endl;dfs(1, 0);for (int i = 1; i <= n; i++) {if (i != 1)printf(" ");printf("%d", color[i]);}printf("\n");}
0 0
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- [Updating]Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)解题报告
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)【A,B,C】
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)A,B,C
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B.(三分)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B.(三分)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C (dfs+vector)
- 【解题报告】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A.B.C
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) A
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) C
- Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals) A. Andryusha and Colored Balloons
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 题解(ABCDE) (二分,dfs序,数据结构)
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Change
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Change
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017
- ActiveMQ集群配置
- HttpServletRequest与HttpServletResponse
- js-句号换行
- 二叉树的前序、中序、后序遍历(递归&非递归)
- c#中的ListView用法
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals
- View在ListView里面画竖线。不显示。显示不全等问题处理
- dsst依赖opencv
- 微信小程序跳转页面传值
- 堆,栈,队列的理解
- 迁址到博客园
- LeetCode:139.Word Break
- 如何修改主机名hostname
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)