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

Svjetlo

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

의견: 0

설명

Oh no! It’s nighttime, and little Fabijan is afraid of the dark. To make things
worse, the chandelier in his room is broken.
The chandelier is made up of \(n\) light bulbs connected by \(n - 1\) wires, so that each
wire connects two bulbs and all bulbs are connected, either directly or through
other bulbs. In other words, the chandelier is a tree.
Each bulb has a button that changes its state. If the bulb is turned off, pressing the button turns it on,
and if it’s on, it turns it off. In the beginning, some bulbs are on and some are off(it’s possible that all
are turned off). All \(n\) bulbs need to be turned on in order for Fabijan to stop being afraid, since only
then will there be enough light in the room.
Fabijan will choose some sequence of bulbs such that bulbs that are consecutive in the sequence are
directly connected by some wire. Bulbs can be repeated. He will then go around the bulbs in order
they appear in the sequence. Since Fabijan reaaaly likes pressing buttons, either on light bulbs, washing
machines, or in elevators, each time he visits a bulb he will press the corresponding button
once, changing its state.
Help Fabijan and determine the length of the shortest sequence of bulbs such that in the end all bulbs
are turned on. There will be at least one bulb that is turned offin the beginning.

제약

Subtask 1 (20 points): \(2 \le n \le 100\)

Subtask 2 (30 points): Each bulb is directly connected with at most two other bulbs.

Subtask 3 (30 points): All bulbs are turned offin the beginning.

Subtask 4 (30 points): No additional constraints.

입력 형식

The first line contanins an integer \(n\), the number of light bulbs. Bulbs are labeled by integers from 1 to \(n\).
The second line contans a sequence of \(n\) characters ’0’ and ’1’. If the \(i-th\) character is equal to ’0’,
then in the beginning the \(i-th\) bulb is turned off, and if it’s equal to ’1’, it’s turned on.
Each of the following \(n - 1\) lines contains two integers \(x\) and \(y\) (\(1 \le x\), \(y \le n\)) – labels of light bulbs that
are directly connected by a wire.

출력 형식

Output the minimum possible length of a sequence such that all bulbs are turned on in the end.
It can be proven that such a sequence always exists.

서브태스크
서브태스크점수설명

1

20점

\(2 \le n \le 100\)

2

30점

Each bulb is directly connected with at most two other bulbs.

3

30점

All bulbs are turned offin the beginning.

4

30점

No additional constraints.

예제 1
입력
3
010
1 2
2 3
출력
4
예제 2
입력
5
00000
1 2
2 3
2 4
3 5
출력
7
예제 3
입력
5
00100
1 2
2 3
2 4
3 5
출력
8
설명

Clarification of the first example:
Fabijan can choose the sequence 1, 2, 3, 2.

문제 정보

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

출처 COCI 2020/2021 Contest 2

평가 및 의견

Svjetlo

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

Log in to rate problems.

개별 의견

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

풀이 제출

Svjetlo

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