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

Picking Flowers

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

*Note: The time limit for this problem is 3s, 1.5x the default.*

Farmer John's farm structure can be represented as a connected undirected graph
with \(N\) vertices and \(M\) unweighted edges
(\(2 \leq N \leq 2 \cdot 10^5, N - 1 \leq M \leq 2 \cdot 10^5\)). Initially,
Farmer John is at his barn, represented by farm \(1\).

Initially, farms \(s_1, s_2, \ldots, s_K\) contain flower fields and farms
\(d_1, d_2, \ldots, d_L\) are destination farms. FJ calls a path pretty if:

  • It starts at farm \(1\).
  • It ends at some destination farm \(x\).
  • There is no shorter path starting at farm \(1\) and ending at farm \(x\).
  • FJ visits all flower fields along the way.

FJ can wave his magic wand and make up to one more farm contain a flower field (if it
doesn't already). However, FJ isn't very decisive. For farms \(f\) numbered \(2\)
through \(N\), after FJ temporarily makes farm \(f\) contain a flower field,
determine if there exists a pretty path.

Note that there are multiple test cases, and each case must be treated
independently.

Problem credits: Chongtian Ma

제약

SCORING

  • Inputs 4-6: \(K = 0\) and \(L = 1\)
  • Inputs 7-9: \(K = 0\)
  • Inputs 10-23: No additional constraints

Problem credits: Chongtian Ma

입력 형식

The first line contains \(T\) (\(1 \leq T \leq 100\)), the number of independent
test cases.

The first line of each test case contains \(N\), \(M\), \(K\), and \(L\)
(\(0 \leq K \leq N - 1, 1 \leq L \leq N - 1\)).

The following line contains \(s_1, s_2, \ldots, s_K\) (\(2 \leq s_i \leq N\), \(s_i\)
are all distinct).

The following line contains \(d_1, d_2, \ldots, d_L\) (\(2 \leq d_i \leq N\), \(d_i\)
are all distinct).

The following \(M\) lines contain \(u\) and \(v\), denoting there is an undirected
edge between farms \(u\) and \(v\). All edges are considered to have equal length.
It is guaranteed that there aren't any multi-edges or self loops.

It is guaranteed that both the sum of \(N\) and the sum of \(M\) do not exceed
\(10^6\) over all test cases.

출력 형식

For each test case, output a binary string of length \(N - 1\). The \(i\)'th
character in the string should be \(1\) if the answer holds true for the
\((i+1)\)'th farm.

예제 1
입력
1
7 7 0 1

5
1 2
2 3
3 4
4 5
5 6
6 7
3 6
출력
111110
설명

Since \(5\) is the only destination farm, the answer holds true if the \(i\)'th farm
lies on any shortest path from \(1\) to \(5\).

There are two shortest paths from \(1\) to \(5\), which are
$1 \rightarrow 2 \rightarrow
3 \rightarrow 4 \rightarrow 5$ and
$1 \rightarrow 2 \rightarrow
3 \rightarrow 6 \rightarrow 5$.

Since there are no farms that already contain flower fields, the answer for farm
\(i\) holds true if farm \(i\) lies on at least one of the two aforementioned paths.

예제 2
입력
1
6 6 0 2

5 3
1 2
2 3
3 4
4 5
5 6
2 5
출력
11010
설명

There are two destination farms: \(5\) and \(3\). Since there are no farms that
already contain flower fields, the \(i\)'th farm must lie on a shortest path to
either \(5\) or \(3\). Since farm \(2\) lies on a shortest path to farm \(5\), so the
answer holds for farm \(2\). Trivially, farm \(3\) lies on the shortest path to farm
\(3\) and farm \(5\) lies on the shortest path to farm \(5\).

예제 3
입력
3
4 3 2 1
2 3
4
1 2
2 3
3 4
4 4 2 1
2 3
4
1 2
1 3
2 4
3 4
5 5 2 1
2 4
5
1 2
1 3
2 4
3 4
4 5
출력
111
000
1011
설명

For the first test case, the answer holds true for the \(i\)'th farm if FJ can
pass through farm \(i\), farm \(2\), and farm \(3\) (in no particular order) on some
shortest path to farm \(4\). It can be shown that the answer holds true for all
farms.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Third Contest > Gold

태그

평가 및 의견

Picking Flowers

개요
출제자 난이도 Gold II 골드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Picking Flowers

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