RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0416 파일 입출력

Clock Tree

Platinum V 플래티넘 V
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John's new barn has a truly strange design: it consists of \(N\) rooms
(\(2 \leq N \leq 2500\)), conveniently numbered \(1 \ldots N\), and \(N-1\) corridors.
Each corridor connects a pair of rooms, in such a way that it is possible to
walk from any room to any other room along a series of corridors.

Every room in the barn has a circular clock on the wall with the standard
integers \(1 \ldots 12\) around its face. However, these clocks only have one
hand, which always points directly at one of the integers on the clock face (it
never points between two of these integers).

Bessie the cow wants to synchronize all the clocks in the barn so they all point
to the integer 12. However, she is somewhat simple-minded, and as she walks
around the barn, every time she enters a room, she moves the hand on its clock
ahead by one position. For example, if the clock pointed at 5, it would now
point at 6, and if the clock pointed at 12, it would now point at 1. If Bessie
enters the same room multiple times, she advances the clock in that room every
time she enters.

Please determine the number of rooms in which Bessie could start walking around
the barn such that she could conceivably set all the clocks to point to 12.
Note that Bessie does not initially advance the clock in her starting room, but
she would advance the clock in that room any time she re-entered it. Clocks do
not advance on their own; a clock only advances if Bessie enters its room.
Furthermore, once Bessie enters a corridor she must exit through the other end
(it is not allowed to walk partially through the corridor and loop back around
to the same room).

Problem credits: Brian Dean

제약

SCORING

  • Test cases 2-7 satisfy \(N\le 100\).
  • Test cases 8-15 satisfy no additional constraints.

Problem credits: Brian Dean

입력 형식

The first line of input contains \(N\). The next line contains \(N\) integers, each
in the range \(1 \ldots 12\), specifying the initial clock setting in each room.
The next \(N-1\) lines each describe a corridor in terms of two integers \(a\) and
\(b\), each in the range \(1 \ldots N\), giving the room numbers connected by the
corridor.

출력 형식

Print the number of rooms in which Bessie could start, such that it is possible
for her to set all clocks to point to 12.

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 clocktree.in
출력을 쓸 파일 clocktree.out
예제 1
입력
4
11 10 11 11
1 2
2 3
2 4
출력
1
설명

In this example, Bessie can set all the clocks to point to 12 if and only if she starts
in room 2 (for example, by moving to room 1, 2, 3, 2, and finally 4).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2019-2020 > February > Silver

태그

평가 및 의견

Clock Tree

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Clock Tree

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