#P15114. [集训队论文 2026] 无处存储

    ID: 17025 远端评测题 3000~8000ms 32~512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>点分治Special Judge凸完全单调性(wqs 二分)树链剖分

[集训队论文 2026] 无处存储

Problem Description

You are given a tree with nn nodes rooted at 11, and nn triples (ai,bi,ci)(a_i,b_i,c_i).

For every s∈[1,k]s\in[1,k], you need to find a non-negative integer sequence hh of length nn such that:

  • ∀i∈[1,n],hi∈[0,k]\forall i\in[1,n],h_i\in[0,k].
  • ∑i=1nhi=s\sum_{i=1}^nh_i=s.
  • $\forall i\in[1,n],(h_i\bmod 2)\ge\sum_{j\in\mathrm{son}(i)}(g_j\bmod 2)$, where son(i)\mathrm{son}(i) denotes the set of children of node ii, and gjg_j denotes the sum of hh within the subtree of jj.

And you should minimize ∑i=1nf(ai,bi,ci,hi)\sum_{i=1}^nf(a_i,b_i,c_i,h_i), where f(a,b,c,x)=ax2+bx+cf(a,b,c,x)=ax^2+bx+c.

Given op∈{0,1}op\in\{0,1\}, if op=0op=0, you need to output the answers for s=1,2,...,ks=1,2,...,k; if op=1op=1, you need to output the answer for s=ks=k and construct any one optimal solution.

Input Format

This problem contains multiple test cases.

The first line contains three numbers id,op,Tid,op,T, representing the subtask ID, whether you are required to output a solution for s=ks=k, and the number of test cases.

Then for each test case:

The first line contains two numbers n,kn,k.

The second line contains n−1n-1 numbers p2,p3,...,pnp_2,p_3,...,p_n, where pip_i denotes the parent of node ii.

The next nn lines each contain three numbers; the three numbers on the ii-th line are ai,bi,cia_i,b_i,c_i.

Output Format

If op=0op=0, then for each test case, output one line with kk numbers, where the ii-th number is the answer for s=is=i.

If op=1op=1, then for each test case, first output one line with one number, the answer when s=ks=k, and then output one line with nn numbers, where the ii-th number is hih_i, describing an optimal solution when s=ks=k.

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 100%100\% 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 ∑k\sum k.

Subtask ID ∑n≤\sum n\le k≤k\le op=op= Special Property Memory Limit Score
11 1010 55 00 None 512512 MB 55
22 300300 200200
33 2×1042\times 10^4 1.5×1031.5\times 10^3 1515
44 11 1010
55 00 Randomly generated tree shape 3232 MB 55
66 11
77 The tree is a chain 1515
88 00 None 1010
99 11
1010 3×1043\times 10^4 2×1032\times 10^3 00
1111 11

A randomly generated tree shape means that pip_i is generated uniformly at random from [1,i−1][1,i-1].

For subtasks with op=0op=0, the time limit is 33 s.

For subtasks with op=1op=1, the time limit is 88 s.

Translated by ChatGPT 5