{"problem":{"name":"B. Dynamic Diameter","description":{"content":"You are given $n + 1$ nodes and $n -1$ edges where the first $n$ nodes are a tree and node $n + 1$ is in its own component. For each node $i$ from $1... n$, answer the following question: If an edge ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF10269B"},"statements":[{"statement_type":"Markdown","content":"You are given $n + 1$ nodes and $n -1$ edges where the first $n$ nodes are a tree and node $n + 1$ is in its own component. For each node $i$ from $1... n$, answer the following question:\n\nIf an edge was added from node $i$ to node $n + 1$, what would the diameter of the created tree be? (Notice that the $n + 1$ nodes will be a tree if this edge was added).\n\nThe first line will contain a single integer $n$, the number of nodes in the tree initial tree. $n -1$ lines follow, each containing two different integers, describing the edges initially in the tree. Additional constraint on input: these edges will form a tree on the first $n$ nodes.\n\n$1 <= n <= 3 * 10^5$\n\nPrint $n$ integers, each on their own line. The $i$th is the diameter of the new tree if you were to add an edge from node $i$ to node $n + 1$.\n\n## Input\n\nThe first line will contain a single integer $n$, the number of nodes in the tree initial tree. $n -1$ lines follow, each containing two different integers, describing the edges initially in the tree. Additional constraint on input: these edges will form a tree on the first $n$ nodes.$1 <= n <= 3 * 10^5$\n\n## Output\n\nPrint $n$ integers, each on their own line. The $i$th is the diameter of the new tree if you were to add an edge from node $i$ to node $n + 1$.\n\n[samples]","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ T = (V, E) $ be a tree with $ V = \\{1, 2, \\dots, n\\} $ and $ |E| = n - 1 $. Let $ v_{n+1} $ be an isolated node.  \n\nFor each $ i \\in \\{1, \\dots, n\\} $, define $ T_i = (V \\cup \\{v_{n+1}\\}, E \\cup \\{\\{i, v_{n+1}\\}\\}) $, the tree formed by adding edge $ (i, v_{n+1}) $.\n\n**Constraints**  \n$ 1 \\le n \\le 3 \\cdot 10^5 $\n\n**Objective**  \nFor each $ i \\in \\{1, \\dots, n\\} $, compute the diameter of $ T_i $, defined as:  \n$$\n\\text{diam}(T_i) = \\max_{u,v \\in V \\cup \\{v_{n+1}\\}} \\text{dist}_{T_i}(u, v)\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10269B","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}