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.