#P10829. [COTS 2023] 三元图 Graf
[COTS 2023] 三元图 Graf
Background
Translated from Izborne Pripreme 2023 (Croatian IOI/CEOI Team Selection) D1T1. .
Happy birthday to NaCly_Fish! (2024.7.28).
Problem Description
For a non-negative integer , we define a -ternary graph recursively.
- A -ternary graph is an undirected graph.
- For , a -ternary graph is a graph with only node and edges.
- For , a -ternary graph is formed by combining three -ternary graphs. Specifically, choose one node from each of the three -ternary graphs, and then add edges between every pair of these three chosen nodes. The resulting graph is a -ternary graph.
The figure below shows a -ternary graph.

Given an undirected graph , determine whether it is a -ternary graph.
Input Format
The first line contains two positive integers , representing the number of vertices and edges of .
The next lines each contain two positive integers , representing an edge in .
Output Format
If is a -ternary graph, output (Croatian for “yes”); otherwise output (Croatian for “no”).
3 3
1 2
2 3
3 1
da
9 12
1 2
2 3
3 1
3 4
4 5
3 5
5 6
6 7
7 5
7 8
9 8
7 9
ne
9 12
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
1 7
7 4
4 1
da
Hint
Sample Explanation
Sample explanation: this is a -ternary graph.
Constraints
For of the testdata, it is guaranteed that:
- , ;
- .
| Subtask ID | Score | Constraints |
|---|---|---|
| , | ||
| , | ||
| Satisfies the special property | ||
| No additional constraints |
Special property: If is a -ternary graph, it is guaranteed that at each step, the chosen nodes have already been chosen before. In other words, it always chooses the “middle nodes”.
Translated by ChatGPT 5