RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0713

Perfect Binary Trees

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

*Note: The memory limit for this problem is 512MB, twice the default.*

A perfect binary tree is a rooted tree where every non-leaf node has
exactly two children and all leaf nodes are at an equal distance from the root.

An unrooted perfect binary tree is an unrooted tree that is a perfect
binary tree when rooted at one of its nodes.

Bessie has a tree with \(N\) (\(1 \le N \le 10^5\)) nodes. Determine the number of
ways to remove a subset of edges from the tree so that the resulting forest is a
collection of unrooted perfect binary trees. As the answer may be very large,
output the result modulo \(10^9+7\).

Problem credits: Avnith Vijayram

제약

SCORING

  • Inputs 2-3: \(N\le 15\)
  • Inputs 4-5: No node is adjacent to more than two other nodes.
  • Inputs 6-9: \(N\le 1000\), the sum of \(N\) does not exceed \(2000\), and no node is adjacent to more than three other nodes.
  • Inputs 10-13: No node is adjacent to more than three other nodes.
  • Inputs 14-21: No additional constraints.

Problem credits: Avnith Vijayram

입력 형식

The first line contains an integer \(T\) (\(1 \leq T \leq 100\)), the number of
independent test cases.

The first line of each test case contains an integer \(N\).

Each of the next \(N-1\) lines of each test case contains two integers \(u_i\) and
\(v_i\) (\(1 \leq u_i, v_i \leq N\)) indicating an edge between nodes \(u_i\) and
\(v_i\) .

It is guaranteed that for each test case, the given edges form a tree with \(N\)
nodes.

Additionally, the sum of \(N\) over all test cases does not exceed \(2\cdot 10^5\).

출력 형식

For each test case, output a single integer: the number of subsets of edges
that, when removed, result in a forest that is a collection of unrooted perfect
binary trees, modulo \(10^9+7\).

예제 1
입력
3
6
1 2
3 2
4 6
5 6
6 2
3
1 2
3 2
7
2 1
2 3
1 6
1 7
3 4
3 5
출력
8
2
14
설명

In the first test case, Bessie can remove any of the following subsets of edges
to get a forest of perfect binary trees:

  1. \((2, 6)\)
  2. \((1, 2)\), \((2, 3)\), \((2, 6)\)
  3. \((1, 2)\), \((2, 3)\), \((4, 6)\)
  4. \((1, 2)\), \((2, 3)\), \((5, 6)\)
  5. \((1, 2)\), \((4, 6)\), \((5, 6)\)
  6. \((2, 6)\), \((4, 6)\), \((5, 6)\)
  7. \((2, 3)\), \((4, 6)\), \((5, 6)\)
  8. \((1, 2)\), \((2, 3)\), \((2, 6)\), \((4, 6)\), \((5, 6)\)

The first subset results in two subtrees of height \(1\), the last subset results
in six subtrees of height \(0\), and the other subsets result in three subtrees of
height \(0\) and one subtree of height \(1\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > US Open

태그

평가 및 의견

Perfect Binary Trees

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Perfect Binary Trees

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8