| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 71 | 34 | 33 | 51.562% |
The central square of Hangzhou is home to a famous ancient tree, which can be regarded as a rooted tree with $N$ nodes, indexed from $0$ to $N - 1$, with node $0$ being the root.
A node with no children is called a leaf node. Every time the ancient tree sheds its leaves, it selects one leaf node at that time to delete, and it may shed leaves multiple times in the same day.
There are $M$ volunteers (indexed from $0$ to $M - 1$) responsible for guarding the ancient tree. Each of them independently records the leaf-shedding situation of this year, using the following method:
Every day, collect the indices of all newly fallen leaves (i.e. the indices of the nodes which are deleted on that day), and write them down in any order after the previous fallen leaves.
For example: On the first day, leaves $3$ and $4$ fall, so they write down $3, 4$ or $4, 3$. On the second day, leaves $1$ and $2$ fall, so they continue to write down $1, 2$ or $2, 1$. The final record may be any of $(3, 4, 1, 2)$, $(4, 3, 1, 2)$, $(3, 4, 2, 1)$, or $(4, 3, 2, 1)$.
The process lasts for $K$ days, with newly fallen leaves every day, until only the root node remains.
While traveling, you happen to visit Hangzhou. It is now a cold winter. Looking up at the bare branches of the ancient tree, you can't help but imagine the beautiful sight of falling leaves.
You are very curious to know how many days you could have seen falling leaves this year, but you can only find the records of the $M$ volunteers. Try to infer the maximum possible value of $K$ from the records.
You need to implement the following function:
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S);
Note: Since the function will be called more than once, contestants need to pay attention to the impact of the remaining data of the previous call on the current call, especially the state stored in global variables.
Consider the following call:
solve(3, 1, {-1, 0, 0}, {{1, 2}});
The corresponding tree is shown below:
Leaves $1$ and $2$ may fall on the same day, or $1$ may fall first on the first day, followed by $2$ on the second day. The leaf-falling days lasts no more than $2$ days.
Therefore, the procedure should return $2$.
Consider the following call:
solve(5, 2, {-1, 0, 0, 1, 1}, {{1, 2, 3, 4}, {4, 1, 2, 3}});
The corresponding tree is shown below:
Assuming there are at least $2$ leaf-falling days, according to the volunteers' records, leaf $4$ will fall on different days (the first and last), which is contradictory.
Therefore, the procedure should return $1$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 11 | $M = 1$, $N ≤ 10$, $\sum N ≤ 30$. |
| 2 | 14 | $N ≤ 10$, $\sum N ≤ 30$. |
| 3 | 5 | $M = 1$, $N ≤ 1\, 000$, $\sum N ≤ 2\, 000$, $F[i] = i - 1$. |
| 4 | 9 | $M = 1$, $N ≤ 1\, 000$, $\sum N ≤ 2\, 000$. |
| 5 | 5 | $N ≤ 1\, 000$, $\sum N ≤ 2\, 000$, $F[i] = i - 1$. |
| 6 | 11 | $N ≤ 1\, 000$, $\sum N ≤ 2\, 000$. |
| 7 | 9 | $M = 1$, $F[i] = i - 1$. |
| 8 | 11 | $M = 1$. |
| 9 | 9 | $F[i] = i - 1$. |
| 10 | 16 | No additional constraints. |
The sample grader reads the input in the following format:
For each of the following $T$ test cases:
The sample grader prints your answers in the following format:
For each test cases:
solveC++17, C++20, C++17 (Clang), C++20 (Clang)