QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 512 MB Total points: 100

#11278. 56TP

Statistics

给包含 $n$ 个顶点的有根树,每个顶点 $i$ 在时刻 $t$ 有权重 $v(t,i)$。

对每个顶点给出 $v(0,i)$,保证对非叶节点 $i$ 有 $v(0,i)=0$,对叶子 $i$ 有 $0\le v(0,i)\le n$。

共 $m$ 次询问,每次询问给出 $x,y,t$,问 $x$ 到 $y$ 路径上在时刻 $t$ 的权重的最小值、最大值、和。

对叶子 $i$,有 $v(t,i)=v(0,i)$;

对非叶节点 $i$,$t>0$,$v(t,i)$ 是 $i$ 的每个孩子 $j$ 的 $v(t-1,j)$ 的最大值。

输入格式

第一行两个整数 $n,m$。

接下来 $n-1$ 行每行一个整数依次表示 $f_2,\dots,f_n$,其中 $f_i$ 表示节点 $i$ 的父亲,根为 $1$。

接下来 $n$ 行每行一个整数依次表示 $v(0,1),v(0,2),\dots,v(0,n)$。

接下来 $m$ 行,每行三个整数表示 $x,y,t$。

输出格式

输出 $m$ 行,共 $m$ 个整数表示每个询问的答案。

样例数据

样例输入

8 3
1
2
3
3
3
4
4
0
0
0
0
7
5
7
5
7 5 8
1 2 8
8 2 8

样例输出

7 7 28
7 7 14
5 7 26

子任务

Idea:nzhtl1477,Solution:ccz181078,Code:ccz181078,Data:ccz181078

对于 $100\%$ 的数据,满足 $1\le n,m\le 10^6$,$1\le f_i\le i-1$,$0\le v(0,i)\le n$,$1\le x,y,t\le n$。

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.