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

S4. Painting Roads

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

의견: 0

설명

Alanna, the mayor of Kitchener, has successfully improved the city’s
road plan. However, a travelling salesperson from the city of RedBlue
complained that the roads are not colourful enough. Alanna’s second job
is to paint some of the roads.

Kitchener’s road plan can be represented as a collection of \(N\) intersections with \(M\) roads, where the \(i\)-th road connects intersections \(u_i\) and \(v_i\). All roads are initially grey. Alanna
would like to paint some of the roads in red or blue such that the
following condition is satisfied:

  • Whenever there is a grey road that connects \(u_i\) and \(v_i\), there is also a path of roads from
    \(u_i\) to \(v_i\) such that the roads on the path
    alternate between red and blue, without any of the roads on this path
    being grey.

To lower the city’s annual spending, Alanna would like to minimize
the number of painted roads. Can you help Alanna design a plan that
meets all the requirements?

제약

\((1 \le N,M \le 2 \cdot 10^5)\)
\((1 \le u_i,v_i \le N, u_i \ne v_i)\)

Marks

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

Marks Additional Constraints
\(2\) There is a road connecting intersection \(i\) with intersection \(i+1\) for all $1 \le i
Definition: if we denote a road between intersections \(u\) and \(v\) as \(u \leftrightarrow v\), then a simple cycle is a sequence
\(w_1 \leftrightarrow w_2\leftrightarrow \ldots \leftrightarrow w_k \leftrightarrow w_1\) where \(k \geq 3\) and all \(w_i\) are distinct.
입력 형식

The first line contains two integers \(N\) and \(M\) \((1 \le N,M \le 2 \cdot 10^5)\).

The \(i\)-th of the next \(M\) lines contains two integers \(u_i\) and \(v_i\), meaning that there exists a road
from intersection \(u_i\) to
intersection \(v_i\) \((1 \le u_i,v_i \le N, u_i \ne v_i)\).

There is at most one road between any unordered pair of
intersections.

출력 형식

Output a string of \(M\) characters,
representing the paint plan. The \(i\)-th character should be R
if the \(i\)-th road is to be painted
red, B if \(i\)-th road is
to be painted blue, or G (for "grey") if the \(i\)-th road is to be left unpainted.

Remember that you must minimize the number of painted roads while
satisfying the condition. If there are multiple possible such plans,
output any of them.

예제 1
입력
5 7
1 2
2 4
5 2
4 5
4 3
1 3
1 4
출력
RGGRGRB
설명

A diagram of the intersections along with a valid paint plan that
minimizes the number of painted roads is shown below. Note that the
colours are shown on each road as R (red), B (blue), or G (grey).

All the unpainted roads satisfy the condition:

  • The \(2\)nd road, labelled
    G2, connects intersection \(2\) with intersection \(4\). The path through intersections \(2,1,4\) alternates red, blue.

  • The \(3\)rd road, labelled
    G3, connects intersection \(5\) with intersection \(2\). The path through intersections \(5,4,1,2\) alternates red, blue,
    red.

  • The \(5\)th road, labelled
    G5, connects intersection \(4\) with intersection \(3\). The path through intersections \(4,1,3\) alternates blue, red.

예제 2
입력
4 2
1 2
3 4
출력
BB
설명

Note that it is possible for Kitchener to be disconnected.

문제 정보

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

출처 CCC 2024 Senior

평가 및 의견

S4. Painting Roads

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

Log in to rate problems.

개별 의견

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

풀이 제출

S4. Painting Roads

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