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

Deblo

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

의견: 0

설명

1 \(s / 64\) \(MB / 90\) points

About thirty years ago, young Krešo participated for the first time in the national informatics

competition. Similar to today, the opening of the competition consisted of a series of speakers who

tried to demonstrate the importance of this event to the contestants through motivational messages.

The audience, with enthusiasm, began applauding every couple of seconds, but Krešo was irritated

by one sentence. Namely, one of the speakers claimed he was more appreciative of the logical

operation AND than the logical operation \(OR\) because, regardless of the winner’s identity, to him both

Mirko and Slavko were winners of the national competition, instead of the winner being Mirko or

Slavko. Krešo went mad, got up and started explaining to the audience that this is an operation

known as exclusive \(OR\) (popular XOR ). After having given his lecture, he gave the distinguished

speaker the next task to verify his understanding.

There is a given tree consisting of \(N\) nodes, where each node is assigned a value. The value of a

path on that tree is defined as the exclusive \(OR\) of all nodes’ values on that path. Your task is to

determine the sum of the values of all paths of the tree, including paths containing only one node.

Thirty years later, Krešo has finally persuaded the authors of the COCI tasks to include this task in

one of the rounds. Help us return Krešo’s faith in the future of competitive programming.

Note: Exclusive \(OR\) (⊕) is a binary operation that is applied separately on each pair of corresponding

bits of its two operands so that some bit in the result is set to 1 if and only if that bit in exactly one

operand is set to 1.

제약

In test cases worth 30% of total points, \(N\) will be less than or equal to 200.
In test cases worth 50% of total points, \(N\) will be less than or equal to 1000.
In test cases worth additional 20% of total points, each node \(x\) = 1, 2, ... \(N-1\) will be connected to
node \(x + 1\) .

입력 형식

The first line contains a positive integer \(N\) (1 ≤ \(N \le 100\,000\)) that denotes the number of nodes in the

tree.
The second line contains \(N\) integers \(v\) {i} (0 ≤ \(v\) value representing} ≤3 000 000) separated by space, i ^{th

the value of the i {th}{ } node.
The following (\(N-1\)) lines contain two numbers \(a\) {j} and \(b\) (1 ≤ \(a\) {j}{ }, \(b\) _{j} ≤ \(N\) ) that indicate that there is an

edge between the nodes \(a\) {j}{ } and \(b\) {j-}{ }.

출력 형식

Print the required sum of values for all tree paths.

예제 1
입력
1 s / 64 MB / 90 points

3
1 2 3
1 2
2 3

5
2 3 4 2 1
1 2
1 3
3 4
3 5

6
5 4 1 3 3 3
3 1
3 5
4 3
4 2
2 6
출력
output
output
10

64

85
설명

Clarification of the first sample test:

The value of the path from node 1 to node 1 is 1

The value of the path from node 1 to node 2 is 1 ⊕ 2 = 3

The value of the path from node 1 to node 3 is 1 ⊕ 2 ⊕ 3 = 0

The value of the path from node 2 to node 2 is 2

The value of the path from node 2 to node 3 is 2 ⊕ 3 = 1

The value of the path from node 3 to node 3 is 3

The sum of all paths is 1 + 3 + 0 + 2 + 1 + 3 = 10.

문제 정보

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

출처 COCI 2018/2019 Contest 2

평가 및 의견

Deblo

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

Log in to rate problems.

개별 의견

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

풀이 제출

Deblo

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