#P15114. [集训队论文 2026] 无处存储
[集训队论文 2026] 无处存储
Problem Description
You are given a tree with nodes rooted at , and triples .
For every , you need to find a non-negative integer sequence of length such that:
- .
- .
- $\forall i\in[1,n],(h_i\bmod 2)\ge\sum_{j\in\mathrm{son}(i)}(g_j\bmod 2)$, where denotes the set of children of node , and denotes the sum of within the subtree of .
And you should minimize , where .
Given , if , you need to output the answers for ; if , you need to output the answer for and construct any one optimal solution.
Input Format
This problem contains multiple test cases.
The first line contains three numbers , representing the subtask ID, whether you are required to output a solution for , and the number of test cases.
Then for each test case:
The first line contains two numbers .
The second line contains numbers , where denotes the parent of node .
The next lines each contain three numbers; the three numbers on the -th line are .
Output Format
If , then for each test case, output one line with numbers, where the -th number is the answer for .
If , then for each test case, first output one line with one number, the answer when , and then output one line with numbers, where the -th number is , describing an optimal solution when .
0 0 1
5 5
1 1 2 2
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
1 2 3 4 7
0 1 1
5 5
1 1 2 2
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
7
1 1 2 0 1
Hint
For of the data, $1\le T,\sum n\le 3\times 10^4,1\le k\le 2\times 10^3,0\le a_i,|b_i|,|c_i|\le 10^6,1\le p_i<i$. Note that there is no guarantee on the range of .
| Subtask ID | Special Property | Memory Limit | Score | |||
|---|---|---|---|---|---|---|
| None | MB | |||||
| Randomly generated tree shape | MB | |||||
| The tree is a chain | ||||||
| None | ||||||
A randomly generated tree shape means that is generated uniformly at random from .
For subtasks with , the time limit is s.
For subtasks with , the time limit is s.
Translated by ChatGPT 5