Universal Cup Judging System

Universal Cup

Time Limit: 4.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

พิจารณาต้นไม้ที่มี $n$ จุดยอด โดยที่จุดยอด $1$ เป็นราก แต่ละจุดยอด $i$ ในต้นไม้มีน้ำหนัก $p_i$ ซึ่งทำให้ $p_1, p_2, \dots, p_n$ เป็นการเรียงสับเปลี่ยน

ให้ $L_{u,v}$ แทนน้ำหนักมากที่สุดของจุดยอดใด ๆ บนวิถีเชิงเดียวจากจุดยอด $u$ ไปยังจุดยอด $v$ (รวมถึง $u$ และ $v$) ให้ $\operatorname{subtree}(i)$ แทนเซตของจุดยอดที่ประกอบเป็นต้นไม้ย่อยของจุดยอด $i$ เรานิยาม $S_i = \{u \mid u \in \operatorname{subtree}(i) \land L_{u,i} \le p_i\}$ ซึ่งเป็นเซตของจุดยอดที่สามารถไปถึงได้โดยเริ่มจาก $i$ เคลื่อนที่ไปยังจุดยอดลูกเท่านั้น และผ่านเฉพาะจุดยอดที่มีน้ำหนักน้อยกว่าหรือเท่ากับ $p_i$ เท่านั้น ให้ $f_i = |S_i|$ ซึ่งแทนขนาดของเซตของจุดยอดดังกล่าว

เรานิยามค่าของจุดยอดเป็น $q_{f_i}$ โดยที่ $q$ คือลำดับค่าที่กำหนดให้ $q_1, q_2, \dots, q_n$

ตอนนี้เราต้องการคำนวณสำหรับแต่ละคู่ $(i, j)$ เพื่อหาผลรวมของค่าของจุดยอด $i$ สำหรับการจัดวางน้ำหนักทั้งหมดที่สอดคล้องกับ $p_i = j$ เนื่องจากคำตอบอาจมีค่ามาก โปรดแสดงผลลัพธ์มอดูโล $10^9 + 7$

ข้อมูลนำเข้า

บรรทัดแรกประกอบด้วยจำนวนเต็มหนึ่งจำนวน $n$ ($1 \le n \le 700$) ซึ่งแทนจำนวนจุดยอดในต้นไม้

บรรทัดถัดมาประกอบด้วยจำนวนเต็ม $n$ จำนวน ซึ่งแทน $q_1, q_2, \dots, q_n$ ($0 \le q_i < 10^9 + 7$)

อีก $n - 1$ บรรทัดถัดมา แต่ละบรรทัดประกอบด้วยจำนวนเต็มสองจำนวน $u, v$ ซึ่งแทนเส้นเชื่อมในต้นไม้

ข้อมูลส่งออก

แสดงผล $n$ บรรทัด แต่ละบรรทัดประกอบด้วยจำนวนเต็ม $n$ จำนวน บรรทัดที่ $i$ และจำนวนเต็มตัวที่ $j$ แทนคำตอบที่สอดคล้องกันมอดูโล $10^9 + 7$

ตัวอย่าง

ข้อมูลนำเข้า 1

3
1 1 2
1 2
2 3

ข้อมูลส่งออก 1

2 2 4
2 2 2
2 2 2

ข้อมูลนำเข้า 2

4
1 2 3 4
1 2
2 3
1 4

ข้อมูลส่งออก 2

6 10 16 24
6 8 10 12
6 6 6 6
6 6 6 6

ข้อมูลนำเข้า 3

7
3 7 2 4 1 8 9
1 2
1 3
2 4
4 5
3 6
4 7

ข้อมูลส่งออก 3

2160 3120 3168 2952 2160 3720 6480
2160 2640 2640 2412 2208 2280 2880
2160 2640 3120 3600 4080 4560 5040
2160 3120 3648 3744 3408 2640 1440
2160 2160 2160 2160 2160 2160 2160
2160 2160 2160 2160 2160 2160 2160
2160 2160 2160 2160 2160 2160 2160

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1702EditorialOpenAnother SolutionMilmonView

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.