RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00378

Galaksija

Unrated 레이팅 미적용
난이도
1s
시간 제한
64MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

\(4^{th}\) round, December \(19^{th}\) 2015
A long time ago in a galaxy far, far away, there were \(N\) planets. There were also \(N - 1\) interplanetary
paths that connected all the planets (directly or indirectly). In other words, the network of planets
and paths formed a tree. Additionally, each path was enumerated with an integer that denoted the
curiosity of the path.
A pair of planets \(A\), \(B\) is boring if the following holds:
\(A\) and \(B\) are different planets
• travelling between planet \(A\) and \(B\) is possible using one or more interplanetary paths
• binary XOR of the curiosity of all the paths in that travel is equal to 0
Alas, the times have changed and an evil emperor is ruling the galaxy. He decided to use the Force to
destroy all the interplanetary paths in a certain order.
Determine the number of boring pairs of planets before the emperor started the destruction and after
each destruction.

제약

In test cases worth 20% of total points, it will hold \(N\) ⩽1 000.
In test cases worth at least 30% of total points, every path’s curiosity will be equal to 0.

입력 형식

The first line of input contains the integer \(N\) (1 ⩽\(N\) ⩽100 000).
Each of the following \(N - 1\) line contains three integers \(A_{i}\), \(B_{i}\), \(Z_{i}\) (1 ⩽\(A_{i}\), B_{i} ⩽\(N\), 0 ⩽\(Z_{i}\)
1 000 000 000) that denote that planets \(A@@RISE_MATH_BLOCK_0@@i\) are directly connected with a path of curiosity \(Z\)\(i\).
The following line of input contains the permutation of the first \(N - 1\) integers that denote the order
in which the emperor is destroying the paths. If the \(i\)^{th} element of the permutation is \(j\), then the
emperor destroyed the path between planets \(A_{j}\) and \(B_{j}\) in the \(i\)^{th} step.

출력 형식

The output must contain \(N\) lines, the \(k\)^{th} line containing the number of boring pairs \(A\), \(B\) from the
task after the emperor destroyed exactly \(k - 1\) paths.

예제 1
입력
2
1 2 0
1
3
1 2 4
2 3 4
1 2
4
1 2 0
2 3 0
2 4 0
3 1 2
출력
output
output
1
0
1
0
0
6
3
1
0
설명

Clarification of the first example: Before the destruction, the path between planets 1 and 2 is boring. After
destruction, the path between them doesn’t exist anymore.
Clarification of the second example: Before the destruction, pair of planets (1, 3) is boring. Travel between
1 and 3 is no longer possible after the first and after the second destruction, and none of the remaining pairs of
planets is boring.
Clarification of the third example: Notice that in this example each pair of planets with a possible path
between them is boring because all paths have the curiosity 0.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2015/2016 Contest 4

평가 및 의견

Galaksija

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Galaksija

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8