問題一覧 > 通常問題

No.3350 Tree and Two Apples

レベル : / AI推定難易度 : 2400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 5
作問者 : Solalyth / テスター : jupiter_68 tassei903 noya2
お気に入りにしたユーザー ProblemId : 12855 / 自分の提出
問題文最終更新日: 2025-11-13 18:02:57
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 作問ハッカソンコンテスト 003 Day1 (順位表) の他の問題:

Problem Statement

You are given an undirected tree $T$ consisting of $N$ white vertices numbered from $1$ to $N$. The $i$-th edge connects vertices $u_i, v_i$.

For integers $i, j$ between $1$ and $N$ inclusive, let $T(i, j)$ be the tree with $N+2$ vertices obtained by connecting vertex $i$ to a red vertex $N+1$ and connecting vertex $j$ to a green vertex $N+2$. Consider subsets $S$ of $\{(i, j) ~|~ 1 \leq i \leq N, 1 \leq j \leq N\}$ such that, whenever $(i, j) \neq (i', j')$ and $(i, j), (i', j') \in S$, the trees $T(i, j),~ T(i', j')$ are not isomorphic. Output the maximum possible number of elements of such a subset $S$.

Here, "trees $T, T'$ are isomorphic" means that there exists a bijective function $f$ such that, for any integers $i, j$ between $1$ and $N+2$ inclusive, both of the following hold:

  • There is an edge between vertices $i, j$ of $T$ if and only if there is an edge between vertices $f(i), f(j)$ of $T'$.
  • Vertex $i$ of $T$ and vertex $f(i)$ of $T'$ have the same color.

Constraints

  • $2 \leq N \leq 10^5$
  • $1 \leq u_i < v_i \leq N$
  • The given graph is a tree.
  • All input values are integers.

Input

$N$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_{N-1}$ $v_{N-1}$

Output

Output the answer as an integer on a single line.

Sample

Sample 1
Input
5
1 2
2 3
2 4
4 5
Output
17

$(1, 5) \in S$ and $(3, 5) \in S$ cannot both hold.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。