این مسابقه به صورت حضوری در تاریخ ۱۴ آذر ۱۴۰۳ در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار میشود. علاقهمندان میتوانند به صورت همزمان در مسابقه آنلاین که شامل همان سوالات میباشد شرکت کنند.
A long time ago in the University of Tehran, there were N buildings. There were also 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:
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.
The first line of input contains the integer N.
Each of the following line contains three integers , , , that denote that buildings and are directly connected with a path of curiosity .
The following line of input contains the permutation of the first integers that denote the order in which Zein is destroying the paths. If the element of the permutation is j, then Zein destroyed the path between buildings and in the step.
The output must contain N lines, the line containing the number of boring pairs A, B from the task after Zein destroyed exactly paths.