#include<iostream> (30316)#include<cstdio> #include<vector> (30320)#include<cstring> using namespace std; const int maxn = 1e5+10; vector<int> vec[maxn]; int ans[maxn]; char s[] = "RGB"; void dfs(int f, int root,int now, int _now, int nx){ ans[root] = now; for(int i = 0; i < vec[root].size(); i++){ if(vec[root][i] == f) continue; dfs(root, vec[root][i], nx, now, _now); } } int main(){ memset(ans, 0, sizeof(ans)); int n; cin >> n; for(int i = 1; i < n; i++){ int u, v; cin >> u >> v; vec[u].push_back(v); vec[v].push_back(u); } ans[1] = 0; for(int j = 0;j < vec[1].size(); j++){ if(j &; 1) dfs(1, vec[1][j], 1, 0, 2); else dfs(1, vec[1][j], 2, 0, 1); } for(int i = 1; i <= n; i++){ cout << s[ans[i]]; } cout << endl; return 0; }
点赞 1

相关推荐

11-03 13:18
门头沟学院 Java
包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务