1887:Change

时间限制:2 S   /  内存限制:65536 KB
AC:10   /  Submit:37
问题描述

There is a rooted tree with n nodes, number from 1-n. Root’s number is 1.Each node has a value ai.

Initially all the node’s value is 0.

We have q operations. There are two kinds of operations.

1 v x k : a[v]+=x , a[v’]+=x-k (v’ is child of v) , a[v’’]+=x-2*k (v’’ is child of v’) and so on.

2 v : Output a[v] mod 1000000007(109 + 7).

输入描述

First line contains an integer T (1 ≤ T ≤ 3), represents there are T test cases.

In each test case:

The first line contains a number n.

      The second line contains n-1 number, p2,p3,…,pn . pi is the father of i.

      The third line contains a number q.

      Next q lines, each line contains an operation. (“1 v x k”  or  “2 v”)

1n3·105

1pi<i

1q3·105

1vn; 0x<109+7; 0k<109+7

输出描述

For each operation 2, outputs the answer.

样例输入复制样例

1

3

1 1

3

1 1 2 1

2 1

2 2

样例输出

2

1

来源
2017年第八届福建省大学生程序设计竞赛正式赛F

Copyright 2016 - 2024 XUJC ACM Team
闽ICP备2020022076号-1