#P17340. 【MX-X30-T6】布谷鸟钟

【MX-X30-T6】布谷鸟钟

Background

You are right, but a certain four-character game is indeed fun.

Problem Description

You have a rooted tree with root 11.

At node ii, there is a non-negative integer cic_i and a positive integer did_i. You may perform the following operation any number of times:

  • Choose a node uu such that cuc_u is not a multiple of dud_u. Then increase cic_i by 11 for all nodes ii on the path from uu to the root (including both uu and the root).

After performing these operations, find the number of essentially different arrays cc, modulo 998244353998244353.

Input Format

The first line contains an integer nn.

The next nn lines each contain two integers ci,dic_i, d_i.

The next n−1n - 1 lines each contain two integers ui,viu_i, v_i, indicating an edge.

Output Format

Output a single integer, representing the number of essentially different arrays cc modulo 998244353998244353.

2
0 2
1 2
1 2
3

Hint

Let mm be the distance from the farthest node to the root.

Subtask Score Constraints
1 1010 m≤1m \le 1
2 1515 n≤10n \le 10,di≤3d_i \le 3
3 1010 m≤2m \le 2
4 2020 n≤50n \le 50,Special Property A
5 n≤400n \le 400
6 2525 None

Special Property A: It is guaranteed that for 2≤i≤n2 \le i \le n, the parent of node ii in the rooted tree is generated uniformly at random from 1∼i−11 \sim i - 1.

Constraints: For all testdata, 1≤n≤20001 \le n \le 2000, 0≤ci≤1090 \le c_i \le 10^9, 1≤di≤1091 \le d_i \le 10^9.

Translated by ChatGPT 5