結果

問題 No.1436 Rgaph
ユーザー chineristACchineristAC
提出日時 2021-03-19 23:36:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 79,452 KB
最終ジャッジ日時 2024-04-29 19:32:53
合計ジャッジ時間 7,003 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
56,320 KB
testcase_01 AC 50 ms
56,320 KB
testcase_02 AC 48 ms
55,936 KB
testcase_03 AC 47 ms
56,320 KB
testcase_04 AC 48 ms
56,320 KB
testcase_05 WA -
testcase_06 AC 147 ms
78,080 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 52 ms
59,264 KB
testcase_12 AC 52 ms
59,392 KB
testcase_13 AC 52 ms
59,008 KB
testcase_14 AC 64 ms
68,352 KB
testcase_15 AC 55 ms
58,368 KB
testcase_16 AC 63 ms
68,352 KB
testcase_17 AC 68 ms
72,064 KB
testcase_18 AC 65 ms
70,400 KB
testcase_19 AC 67 ms
71,040 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 55 ms
56,356 KB
testcase_29 AC 269 ms
79,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = mi()
edge = [[] for i in range(N)]
idx = {}
for _ in range(M):
    a,b = mi()
    edge[a-1].append(b-1)
    idx[a-1,b-1] = _

for s in range(N):
    visit = [[False,False] for i in range(N)]
    visit[s][0] = True
    stack = [(s,0)]
    while stack:
        v,p = stack.pop()
        for nv in edge[v]:
            if not visit[nv][1-p]:
                visit[nv][1-p] = True
                stack.append((nv,1-p))
    if any(not visit[i][0] for i in range(N)):
        exit(print(-1))

visited = set([0])
res = [0]
pos = edge[0][0]
while pos not in visited:
    visited.add(pos)
    res.append(pos)
    pos = edge[pos][0]

start = -1
k = len(res)
for i in range(k):
    if res[i]==pos:
        start = i
        break

ans = ["" for i in range(M)]
cnt = k - start
red = 0
for i in range(start,k):
    if i!=k-1:
        u,v = res[i],res[i+1]
        if red < (cnt)//2+1:
            ans[idx[u,v]] = "R"
            red += 1
        else:
            ans[idx[u,v]] = "G"

    else:
        u,v = res[i],res[start]
        if red < (cnt)//2+1:
            ans[idx[u,v]] = "R"
            red += 1
        else:
            ans[idx[u,v]] = "G"

for i in range(M):
    if ans[i]=="":
        ans[i] = "G"

p = [-1 for i in range(N)]
for i in range(N):
    if len(edge[i])==1:
        p[i] = edge[i][0]
    else:
        break
else:
    exit(print(-1))

random.shuffle(ans)
print("".join(ans))
0