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

The Chase

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

의견: 0

설명

Bessie is trying to evade the farmers. The farmers own \(N\)
(\(2 \le N \le 5 \cdot 10^5\)) farms with a one way road between the \(i\)-th farm
and the \(a_i\)-th farm (\(1 \le i \le N\), \(a_i \neq i\)). There are \(F\)
(\(1 \le F \le N\)) farmers and the \(i\)-th farmer is initially stationed at farm
\(s_i\) (\(1 \le s_i \le N\), all \(s_i\) unique). At each time step, every farmer
takes the road at their current farm and moves to the next. Bessie gets caught
if she is ever located at the same farm as any farmer.

Suppose Bessie starts at some farm \(b\). At each time step, she has two options:
she can either choose to rest (stay at her current farm) or take the road and
move to the next farm. If she chooses to move, she moves simultaneously with the
farmers. Bessie moves so that she is never caught by any farmer in a finite
number of timesteps.

For each starting farm \(b\) (\(1 \le b \le N\)), find the maximum number of times
Bessie can choose the rest option if she starts at farm \(b\).

Problem credits: Alex Liang

제약

SCORING

  • Input 2: \(N \le 50\)
  • Inputs 3-10: \(N \le 2000\)
  • Inputs 11-20: No additional constraints.

Problem credits: Alex Liang

입력 형식

The first line contains \(N\) and \(F\), the number of farms and the number of
farmers.

The second line contains \(a_1 \ldots a_N\), the one-way roads going out of each
farm.

The third line contains \(s_1 \ldots s_F\), the starting locations of each farmer.

출력 형식

Output \(N\) lines, the \(b\)-th of which must consist of a single integer denoting
the maximum number of times Bessie can choose the rest option if she starts at
farm \(b\). If there is no way for Bessie to ensure she is never caught after a
finite number of timesteps, then output \(-1\). If Bessie can rest an infinite
number of times, then output \(-2\).

예제 1
입력
4 1
2 1 4 3
1
출력
-1
0
-2
-2
설명
  • Farm 1: If Bessie starts at a farm with a farmer, then she is caught immediately, and you should output \(-1\).
  • Farm 2: Bessie must choose to move at every timestep to avoid being caught by the farmer who starts at farm \(1\).
  • Farms 3-4: Bessie can rest an infinite number of times without being caught.
문제 정보

riseoj 작성

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

태그

평가 및 의견

The Chase

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

Log in to rate problems.

개별 의견

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

풀이 제출

The Chase

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