#P10829. [COTS 2023] 三元图 Graf

    ID: 12284 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>点分治2023O2优化COCI(克罗地亚)圆方树

[COTS 2023] 三元图 Graf

Background

Translated from Izborne Pripreme 2023 (Croatian IOI/CEOI Team Selection) D1T1. 2s,0.5G\texttt{2s,0.5G}.

Happy birthday to NaCly_Fish! (2024.7.28).

Problem Description

For a non-negative integer kk, we define a kk-ternary graph recursively.

  • A kk-ternary graph is an undirected graph.
  • For k=0k=0, a kk-ternary graph is a graph with only 11 node and 00 edges.
  • For k>0k>0, a kk-ternary graph is formed by combining three (k1)(k-1)-ternary graphs. Specifically, choose one node from each of the three (k1)(k-1)-ternary graphs, and then add edges between every pair of these three chosen nodes. The resulting graph is a kk-ternary graph.

The figure below shows a 33-ternary graph.

Given an undirected graph GG, determine whether it is a kk-ternary graph.

Input Format

The first line contains two positive integers N,MN, M, representing the number of vertices and edges of GG.

The next MM lines each contain two positive integers u,vu, v, representing an edge (u,v)(u, v) in GG.

Output Format

If GG is a kk-ternary graph, output da\texttt{da} (Croatian for “yes”); otherwise output ne\texttt{ne} (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 33 explanation: this is a 22-ternary graph.

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1N2000001\le N\le 200\, 000, 0M3000000\le M\le 300\, 000;
  • 1u,vN1\le u,v\le N.
Subtask ID Score Constraints
11 1515 N10N \leq 10, M20M\le 20
22 2020 N1000N \leq 1000, M2000M\le 2000
33 1515 Satisfies the special property
44 5050 No additional constraints

Special property: If GG is a kk-ternary graph, it is guaranteed that at each step, the 33 chosen nodes have already been chosen before. In other words, it always chooses the “middle nodes”.

Translated by ChatGPT 5