시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 | 1024 MB | 23 | 7 | 6 | 60.000% |
Dragonflies can be seen around ponds at Botanic Gardens and Bishan Park. In one of the denser forested areas, Benson the Rabbit has noted down $n$ ponds that the dragonflies fly around. At pond $i$ ($1 ≤ i ≤ n$), there are $b[i]$ bugs that the dragonflies can eat. The bugs at pond $i$ belong to species $s[i]$.
Benson has also noted down $n - 1$ trails. Each trail $j$ ($1 ≤ j < n$) connects 2 distinct ponds $u[j]$ and $v[j]$ bidirectionally. Dragonflies can travel from any pond to any other pond using only the trails.
Benson has captured $d$ dragonflies and intends to release them one at a time at pond $1$. Dragonfly $k$ ($1 ≤ k ≤ d$) has a home pond of $h[k] \ne 1$ and will travel to pond $h[k]$ without visiting any pond more than once using only the trails. These dragonflies will be released in increasing order from dragonfly $1$ to dragonfly $d$. After a dragonfly is released, it will eat a single bug (if there is one or more bugs remaining) at every pond that it visits (including pond $1$), reducing the number of bugs at each of those ponds by $1$ if it is not $0$.
Help Benson determine the number of distinct species of bugs eaten during the journey of each of the $d$ dragonflies.
The input format is as follows:
Output a single line with $d$ spaced integers. The $k$th of these integers should be the number of distinct species of bugs eaten by the $k$th dragonfly.
번호 | 배점 | 제한 |
---|---|---|
1 | 10 | $n, d ≤ 1000$ |
2 | 10 | $d ≤ 2 · 10^5$, $b[i] = d$ (for all $1 ≤ i ≤ n$) |
3 | 12 | $d ≤ 2 · 10^5$, $b[i] ≤ 10$ (for all $1 ≤ i ≤ n$) |
4 | 12 | $d ≤ 2 · 10^5$, $u[j] = j$, $v[j] = j + 1$ (for all $1 ≤ j ≤ n - 1$) |
5 | 37 | $d ≤ 2 · 10^5$, $s[i] = i$ (for all $1 ≤ i ≤ n$) |
6 | 16 | $d ≤ 2 · 10^5$ |
7 | 3 | No additional restrictions |
5 6 4 1 0 3 1 1 3 2 2 1 2 5 4 3 4 2 5 2 2 1 1 4 1 3
2 1 2 1 1 0
The input can be visualized using the below figure where □ represents a bug of species 1, △ represents a bug of species 2, and ⋄ represents a bug of species 3.
Initially, the bug configuration matches that of the left diagram. When the first dragonfly flies to pond 2, 1 bug each of species 1 and 2 is eaten. The configuration changes to the right diagram.
After that, a dragonfly flies to pond 5. It eats a bug from pond 1 and a bug from pond 5. Note that it does not eat any bugs from pond 2 because there are no more bugs left in pond 2. Although 2 bugs are eaten in total, they are of the same species □, so only 1 distinct species of bugs is eaten.
This testcase is valid for subtasks 1, 3, 6 and 7.
7 4 0 2 4 4 0 1 3 6 1 6 2 2 2 1 7 5 2 4 4 1 4 5 6 2 1 6 1 3 6 7
2 1 1 1
This testcase is valid for subtasks 1, 3, 6 and 7.
Olympiad > National Olympiad in Informatics (Singapore) > Qualification > NOI 2022 Qualification 3번