Codeforces 321C Ciel The Commander tree divided into nude topics

Source: Internet
Author: User

Topic links

Test instructions

Given a tree, use the letter A-Z to fill each node
Letters can be used infinitely, but a can only be used once
Target: For any two nodes of the same letter, the path between them must have at least one node of the letter smaller than their
For example, there must be at least one a or a b between two C
Q: Output filling scheme.
Tree can be divided, up to support 2^25 nodes, no solution.
#include <iostream> #include <string> #include <vector> #include <cstring> #include <cstdio > #include <map> #include <queue> #include <algorithm> #include <stack> #include <cstring > #include <cmath> #include <set> #include <vector>using namespace std;template <class t>  inline BOOL Rd (T &ret) {char c; int sgn;if (c = GetChar (), c = = EOF) return 0;while (c! = '-' && (c< ' 0 ' | | C> ' 9 ')) C = GetChar (); sgn = (c = = '-')? -1:1;ret = (c = = '-')? 0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' &&c <= ' 9 ') ret = ret * + (C-' 0 '); ret *= Sgn;return 1;} Template <class t>inline void pt (T x) {if (x < 0) {Putchar ('-'); x =-X;} if (x > 9) pt (X/10);p Utchar (x% 10 + ' 0 ');} typedef long Long Ll;typedef pair<int, int> pii;const int inf = 1e9;const int N = 1e5+10;int n;int num[n], dp[n], si Z, Root;bool vis[n];vector<int>g[n];char s[n];void getroot (int u, int fa) {Dp[u] = 0; Num[u] = 1;for (Auto V:g[u]) {if (Vis[v] | | v = = FA) Continue;getroot (V, u); num[u] + = num[v];DP [u] = max (Num[v], dp[u]);} Dp[u] = max (Dp[u], siz-num[u]); if (Dp[u] < dp[root]) root = u;} void work (int u, int fa, int dep) {root = 0; siz = num[u];getroot (U, FA); S[root] = dep + ' A '; vis[root] = true;for (Auto V : G[root]) {if (Vis[v]) continue;work (V, u, dep + 1);}} void Init () {dp[0] = num[1] = n;memset (Vis, 0, sizeof vis);} int main () {rd (n); for (int i = 1, u, v; i < n; i++) {rd (U); Rd (v); G[u].push_back (v); G[v].push_back (u);} Init (); Work (1, 1, 0); for (int i = 1; I <= n; i++) Putchar (S[i]), Putchar ("); return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 321C Ciel The Commander tree divided into nude topics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.