C. Andryusha and Colored Balloons
来源:互联网 发布:京东众包软件打不开 编辑:程序博客网 时间:2024/06/05 18:18
题意:对于n个顶点,n-1条边的图形,给n个点染色,每连续的3点的颜色不相同,求需要最小颜色数量,并给出染色情况。
最小颜色数量其实,为 min(点的度+1)。对于某点i染色来说,记录i前的颜色,i的颜色,i相邻的点的颜色和前两者不相同。
#include<bits\stdc++.h>using namespace std;vector<int> G[200005];int col[200005],par[200005];int main(){ int n;scanf("%d",&n); for(int i=1;i<n;i++) { int x,y;scanf("%d%d",&x,&y); G[x].push_back(y); G[y].push_back(x); } queue<int> Q; col[1]=1; par[1]=1; Q.push(1); int k = -1; while(!Q.empty()) { int node = Q.front(); Q.pop(); int num = 1; for(int i=0;i<G[node].size();i++) { if(!col[ G[node][i] ]) { if(col[node] == num || col[ par[node] ] == num) num++; if(col[node] == num || col[ par[node] ] == num) num++; col[ G[node][i] ] = num; k = max(k,num); par[ G[node][i] ] = node; num++; Q.push(G[node][i]); } } } printf("%d\n",k); for(int i=1;i<=n;i++) { printf("%d ",col[i]); } printf("\n"); return 0;}
0 0
- C. Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons
- C. Andryusha and Colored Balloons
- 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
- codeforces781A Andryusha and Colored Balloons
- Codeforces 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 div2 C. Andryusha and Colored Balloons
- Codeforces 782C Andryusha and Colored Balloons(BFS)
- Codeforces Round #403 (Div. 2) C. Andryusha and Colored Balloons
- codeforces 782C Andryusha and Colored Balloons【构造】
- css
- 泛型[3]泛型嵌套
- tomcat另建工作区(workspace)
- ROSArduinoBridge中PID 在 ros端 与arduino端的工作机制
- HDU 1029 Ignatius and the Princess IV
- C. Andryusha and Colored Balloons
- 装配Bean
- Android -- RecyclerView实现顶部吸附效果
- 斐波那契堆(Fibonacci Heap)
- Swift Web 开发之 Vapor
- AppleScript: match and delete files in folder
- CodeForces782B The Meeting Place Cannot Be Changed 三分查找
- python 发送163邮件554 DT:SPM
- height:auto和height:100%的区别