این مسابقه به صورت حضوری در تاریخ ۱۴ آذر ۱۴۰۳ در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار می‌شود. علاقه‌مندان می‌توانند به صورت همزمان در مسابقه آنلاین که شامل همان سوالات می‌باشد شرکت کنند.

Network of Buildings


  • محدودیت زمان: ۲ ثانیه
  • محدودیت حافظه: ۶۴ مگابایت

A long time ago in the University of Tehran, there were N buildings. There were also N1N-1 pathways that connected all the buildings (directly or indirectly). In other words, the network of buildings and paths formed a tree. Additionally, each path was enumerated with an integer that denoted the curiosity of the path.

A pair of buildings A, B is boring if the following holds:

  • A and B are different buildings
  • travelling between building A and B is possible using one or more pathways
  • binary XOR of the curiosity of all the paths in that travel is equal to 0

Unfortunately, times have changed, and an evil dean named Zein is now ruling the department. He decided to use the Force to destroy all the pathways in a certain order. Determine the number of boring pairs of buildings before Zein started the destruction and after each destruction.

Input🔗

The first line of input contains the integer N.

Each of the following N1N-1 line contains three integers aia_i, bib_i, ziz_i, that denote that buildings aia_i and bib_i are directly connected with a path of curiosity ziz_i.

The following line of input contains the permutation of the first N1N-1 integers that denote the order in which Zein is destroying the paths. If the ithi^{th} element of the permutation is j, then Zein destroyed the path between buildings aia_i and bib_i in the ithi^{th} step.

Output🔗

The output must contain N lines, the kthk^{th} line containing the number of boring pairs A, B from the task after Zein destroyed exactly k1k-1 paths.

Constraints🔗

  • 1N1051 \leq N \leq 10^5
  • 1ai,biN1 \leq a_i,b_i \leq N
  • 0zi1090 \leq z_i \leq 10^9

Sample Test Data🔗

input 1🔗

3
1 2 5
2 3 5
2 1
Plain text

output 1🔗

1
0
0
Plain text

input 2🔗

4
1 2 0
2 3 0
2 4 0
3 1 2
Plain text

output 2🔗

6
3
1
0
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.