포럼
문제 ICPC00164

D. Digi Comp II

설명

The Digi Comp II is a machine where balls enter from the top and find their way to the bottom via a certain circuit defined by switches. Whenever a ball falls on a switch it either goes to the left or to the right depending on the state of the switch and flips this state in the process. Abstractly it can be modelled by a directed graph with a vertex of outdegree \(2\) for each switch and in addition a designated end vertex of outdegree \(0\). One of the switch vertices is the start vertex, it has indegree \(0\). Each switch vertex has an internal state (L/R). A ball starts at the start vertex and follows a path down to the end vertex, where at each switch vertex it will pick the left or right outgoing edge based on the internal state of the switch vertex. The internal state of a vertex is flipped after a ball passes through. A ball always goes down and therefore cannot get into a loop.

One can "program" this machine by specifying the graph structure, the initial states of each switch vertex and the number of balls that enter. The result of the computation is the state of the switches at the end of the computation. Interestingly one can program quite sophisticated algorithms such as addition, multiplication, division and even the stable marriage problem. However, it is not Turing complete.

제약
입력 형식

The input consists of:
- one line with two integers \(n\) (\(0\le n\le10^{18}\)) and \(m\) (\(1\le m\le 500\,000\)), the number of balls and the number of switches of the graph;
- \(m\) lines describing switches \(1\) to \(m\) in order. Each line consists of a single character \(c\) ('L' or 'R') and two integers \(L\) and \(R\) (\(0\le L,R\le m\)), describing the initial state (\(c\)) of the switch and the destination vertex of the left (\(L\)) and right (\(R\)) outgoing edges. \(L\) and \(R\) can be equal.

Vertex number \(0\) is the end vertex and vertex \(1\) is the start vertex. There are no loops in the graph, i.e., after going through a switch a ball can never return to it.

출력 형식

Output one line with a string of length \(m\) consisting of the characters 'L' and 'R', describing the final state of the switches (\(1\) to \(m\) in order).

예제 1
입력
5 3
L 2 3
R 0 3
L 0 0
출력
RLL
문제 정보

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

출처 ICPC NWERC 2014

평가 및 의견

D. Digi Comp II

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

Log in to rate problems.

개별 의견

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

풀이 제출

D. Digi Comp II

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