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

Switch Grass

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

의견: 0

설명

Farmer John has recently been experimenting with cultivating different types of
grass on his farm, realizing that different types of cows like different types
of grass. However, he must be careful to ensure that different types of grass
are planted sufficiently far away from each-other, in order to prevent them from
being inextricably mixed.

FJ's farm consists of \(N\) fields (\(1 \leq N \leq 200,000\)), where \(M\) pairs of
fields are connected by bi-directional pathways (\(1 \leq M \leq 200,000\)).
Using these pathways, it is possible to walk from any field to any other field.
Each pathway has an integer length in the range \(1 \ldots 1,000,000\). Any pair
of fields will be linked by at most one direct pathway.

In each field, FJ initially plants one of \(K\) types of grass
(\(1 \leq K \leq N\)). Over time, however, he might decide to switch the grass in
some field to a different type. He calls this an "update" operation. He might
perform several updates over the course of time, which are all cumulative in
nature.

After each update, FJ would like to know the length of the shortest path between
two fields having different grass types. That is, among all pairs of fields
having different grass types, he wants to know which two are closest. Ideally,
this number is large, so he can prevent grass of one type from mixing with grass
of another type. It is guaranteed that the farm will always have at least two
fields with different grass types.

In 30 percent of the input cases, each field will be directly connected to at most
10 pathways.

Problem credits: Lewin Gan

제약

Problem credits: Lewin Gan

입력 형식

The first line of input contains four integers, \(N\), \(M\), \(K\), and \(Q\), where
\(Q\) is the number of updates (\(1 \leq Q \leq 200,000\)). The next \(M\) lines
describe the paths; each one contains three integers \(A\), \(B\), and \(L\),
indicating a path from field \(A\) to field \(B\) (both integers in the range
\(1 \ldots N\)) of length \(L\). The next line indicates the initial type of
grass growing in each field (\(N\) integers in the range \(1 \ldots K\)). Finally, the
last \(Q\) lines each describe an update, specified by two integers \(A\) and \(B\),
where the grass in field \(A\) is to be updated to type \(B\).

출력 형식

For each update, print the length of the shortest path between two fields with
different types of grass, after the update is applied.

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

riseoj 작성

출처 올림피아드 > USACO > 2016-2017 > US Open > Platinum

태그

평가 및 의견

Switch Grass

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

Log in to rate problems.

개별 의견

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

풀이 제출

Switch Grass

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