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

S5. Good Influencers

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

의견: 0

설명

There are \(N\) (\(N \ge 2\)) students in a computer science
class, with distinct student IDs ranging from \(1\) to \(N\). There are \(N-1\) friendships amongst the students,
with the \(i\)th being between students
\(A_i\) and \(B_i\) (\(A_i \not= B_i\), \(1 \le A_i \le N\)
and \(1 \le B_i \le N\)). Each pair of
students in the class are either friends or socially connected. A pair
of students \(a\) and \(b\) are socially connected if there exists
a set of students \(m_1, m_2, \ldots, m_k\) such that

  • \(a\) and \(m_1\) are friends,

  • \(m_i\) and \(m_{i+1}\) are friends (for \(1 \leq i \leq k-1\)), and

  • \(m_k\) and \(b\) are friends.

Initially, each student \(i\) either
intends to write the CCC (if \(P_i\) is
Y) or does not intend to write the CCC (if
\(P_i\) is
N). Initially, at least one student intends to
write the CCC, and at least one student does not intend to write the
CCC.

The CCC has allocated some funds to pay some students to be
influencers for the CCC. The CCC will repeatedly choose one student
\(i\) who intends to write the CCC, pay
them \(C_i\) dollars, and ask them to
deliver a seminar to all of their friends, and then all of their friends
will intend to write the CCC.

Help the CCC determine the minimum cost required to have all of the
students intend to write the CCC.

제약

\(N \ge 2\)
\(1 \le A_i \le N\)
\(1 \le B_i \le N\)
\(1 \leq i \leq k-1\)
\(1 \leq i \leq N-1\)

Marks

The following table shows how the available 15 marks are
distributed.

Marks Awarded Number of students Payment Additional Constraints
5 marks \(2 \le N \leq 2\ 000\) \(1 \le C_i \le 1\ 000\) \(A_i = i\) and \(B_i = i+1\) for each \(i\)
7 marks \(2 \le N \leq 2\ 000\) \(1 \le C_i \le 1\ 000\) None
3 marks \(2 \le N \leq 200\ 000\) \(1 \le C_i \le 1\ 000\) None
입력 형식

The first line contains the integer \(N\).

The next \(N-1\) lines each contain
two space-separated integers, \(A_i\)
and \(B_i\) (\(1 \leq i \leq N-1\)).

The next line contains \(N\)
characters, \(P_{1}\ldots P_{N}\), each
of which is either Y or
N.

The next line contains \(N\)
space-separated integers, \(C_{1}\ldots C_{N}\).

출력 형식

Output the minimum integer number of dollars required to have all of
the students to intend to write the CCC.

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

The CCC should pay $6 to student 3 to deliver a seminar to their
friends (students 2 and 4), after which all 4 students will intend to
write the CCC.

예제 2
입력
15
1 5
5 2
2 15
15 4
2 10
8 3
3 1
1 6
11 6
12 6
11 9
11 14
12 7
13 7
NNYYYNYYNNNNNNN
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
출력
6
설명

One optimal strategy is for the CCC to ask students 5, 1, 6, 11, 7,
and 2 to deliver seminars, in that order, paying them $1 each.

문제 정보

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

출처 CCC 2022 Senior

평가 및 의견

S5. Good Influencers

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

Log in to rate problems.

개별 의견

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

풀이 제출

S5. Good Influencers

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