A. Circumference of a Tree

Codeforces
IDCF10269A
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Hopefully you know how to find the diameter of a tree. That's the first part of tree basics, after all! But this problem is completely different: now, you need to find the *circumference* of a tree! As you probably know, pi is equal to the ratio between something's circumferance and its diameter. Also, as you may not know, math is a lie and *pi is really equal to 3*. Rumor has it, this is where the number tree(3) comes from. Assuming pi equals 3, what is the circumference of the given tree? The first line will contain a single integer $n$, the number of nodes in the tree. $n -1$ lines follow, each containing two different integers, describing the edges of the tree. Additional constraint on input: these edges will form a tree. $1 <= n <= 3 * 10^5$ Output a single integer: the circumference of the tree. ## Input The first line will contain a single integer $n$, the number of nodes in the tree. $n -1$ lines follow, each containing two different integers, describing the edges of the tree. Additional constraint on input: these edges will form a tree.$1 <= n <= 3 * 10^5$ ## Output Output a single integer: the circumference of the tree. [samples]
**Definitions** Let $ T = (V, E) $ be a tree with $ n $ nodes and $ n-1 $ edges. Let $ d(u, v) $ denote the shortest path distance (number of edges) between nodes $ u $ and $ v $ in $ T $. Let $ \text{diam}(T) = \max_{u,v \in V} d(u, v) $ be the diameter of the tree. **Constraints** 1. $ 1 \le n \le 3 \times 10^5 $ 2. The graph is a tree (connected, acyclic, undirected). **Objective** Given $ \pi = 3 $, compute the circumference of the tree: $$ \text{circumference} = \pi \cdot \text{diam}(T) = 3 \cdot \text{diam}(T) $$ Output this value as an integer.
API Response (JSON)
{
  "problem": {
    "name": "A. Circumference of a Tree",
    "description": {
      "content": "Hopefully you know how to find the diameter of a tree. That's the first part of tree basics, after all! But this problem is completely different: now, you need to find the *circumference* of a tree! ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Hopefully you know how to find the diameter of a tree. That's the first part of tree basics, after all! But this problem is completely different: now, you need to find the *circumference* of a tree!\n\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T = (V, E) $ be a tree with $ n $ nodes and $ n-1 $ edges.  \nLet $ d(u, v) $ denote the shortest path distance (number of edges) between nodes $ u $ and $ v $ in $ T $.  \nLet $...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments