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

S3. Phonomenal Reviews

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

의견: 0

설명

Jo is a blogger, specializing in the critique of restaurants. Today,
she wants to visit all the Vietnamese Pho restaurants in the Waterloo
area, in order to determine which one is the best.

There are \(N\) restaurants in the
city of Waterloo, numbered \(0\) to
\(N-1\). However, only \(M\) of them are Pho restaurants. Jo can
choose to start at any restaurant. There are \(N-1\) roads in Waterloo, each road
connecting exactly two restaurants. It is possible to reach every
restaurant from any restaurant using these roads. It takes Jo exactly 1
minute to travel along any road.

In computer science, a road network with this structure is called a
tree. Here are three examples of trees:

One property that is true for all trees is that
there is exactly one path that does not repeat any roads between any two
points in the tree.

What is the minimal length of time that Jo needs to spend on
travelling on roads to visit all of the Pho restaurants?

제약

\((2 \leq M \leq N \leq 100\ 000)\)
\((0 \leq a_i , b_i \leq N-1)\)
\(N \leq 100\)
\(M \leq 3\)
\(M \leq 8\)
\(M \leq N \leq 1000\)

입력 형식

The first line of input contains 2 integers, \(N\) and \(M\) \((2 \leq M \leq N \leq 100\ 000)\).

The second line of input contains \(M\) distinct integers indicating the
restaurants which are Pho restaurants.

The next \(N\)-1 lines contain 2
integers each. The \(i\)-th line
contains \(a_i\) and \(b_i\), \((0 \leq a_i , b_i \leq N-1)\), representing a path between the two
restaurants numbered \(a_i\) and \(b_i\).

For 3 of the 15 available marks, \(M = 2\) and \(N \leq 100\).

For an additional 3 of the 15 available marks, \(M \leq 3\) and \(N \leq 100\).

For an additional 3 of the 15 available marks, \(M \leq 8\) and \(N \leq 100\).

For an additional 4 of the 15 available marks, \(M \leq N \leq 1000\).

출력 형식

Your program should output one line, containing one integer - the
minimum amount of time Jo needs to spend travelling on roads in order to
visit all Pho restaurants, in minutes.

예제 1
입력
8 2
5 2
0 1
0 2
2 3
4 3
6 1
1 5
7 3
출력
3
설명

The path between \(5\) and \(2\) goes through \(5 \rightarrow 1 \rightarrow 0 \rightarrow 2\), which uses 3 roads.

예제 2
입력
8 5
0 6 4 3 7
0 1
0 2
2 3
4 3
6 1
1 5
7 3
출력
7
설명

If Jo begins at restaurant 6, she will only need to use 7 roads. One
possible path that she can take is: \(6 \to 1 \to 0 \to 2 \to 3 \to 7 \to 3 \to 4\). Notice that she doesn’t
need to visit restaurant 5, since it is not a Pho restaurant. A diagram
of the road network is shown below:

문제 정보

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

출처 CCC 2016 Senior

평가 및 의견

S3. Phonomenal Reviews

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

Log in to rate problems.

개별 의견

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

풀이 제출

S3. Phonomenal Reviews

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