結果

問題 No.1436 Rgaph
ユーザー tyawanmusityawanmusi
提出日時 2021-03-13 14:27:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,429 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-04-23 06:21:09
合計ジャッジ時間 5,522 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
11,392 KB
testcase_01 AC 37 ms
11,264 KB
testcase_02 AC 39 ms
11,392 KB
testcase_03 AC 36 ms
11,264 KB
testcase_04 WA -
testcase_05 AC 36 ms
11,264 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 64 ms
19,328 KB
testcase_12 AC 64 ms
19,456 KB
testcase_13 AC 60 ms
19,584 KB
testcase_14 AC 66 ms
18,688 KB
testcase_15 AC 46 ms
14,976 KB
testcase_16 AC 65 ms
19,200 KB
testcase_17 AC 68 ms
19,584 KB
testcase_18 AC 70 ms
19,456 KB
testcase_19 AC 70 ms
19,328 KB
testcase_20 AC 49 ms
14,720 KB
testcase_21 AC 47 ms
13,824 KB
testcase_22 AC 59 ms
17,024 KB
testcase_23 AC 68 ms
19,712 KB
testcase_24 AC 66 ms
19,584 KB
testcase_25 AC 67 ms
18,816 KB
testcase_26 AC 75 ms
19,840 KB
testcase_27 AC 73 ms
19,712 KB
testcase_28 WA -
testcase_29 AC 74 ms
19,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from random import randint
input = lambda:sys.stdin.readline().rstrip()
sys.setrecursionlimit(1007)


def scc(n, edge):
  redge=[[]for _ in range(n)]
  for i in range(n):
    for j in edge[i]:
      redge[j].append(i)
  order=[]
  used=[0]*n
  group=[-1]*n
  def dfs(u):
    used[u]=1
    for v in edge[u]:
      if not used[u]:
        dfs(v)
    order.append(u)
  def rdfs(u,c):
    group[u]=c
    used[u]=1
    for v in redge[u]:
      if not used[v]:
        rdfs(v,c)
  for i in range(n):
    if not used[i]:
      dfs(i)
  used=[0]*n
  x=0
  for u in order[::-1]:
    if not used[u]:
      rdfs(u,x)
      x+=1
  return x,group

def bipartite_graph_check(n, edge):
  color = [-1] * n
  for i in range(n):
    if color[i] != -1:
      continue
    stack = [i]
    color[i] = 0
    for node in stack:
      for mode in edge[node]:
        if color[mode] == -1:
          stack.append(mode)
          color[mode] = color[node] ^ 1
        elif color[mode] == color[node]:
          return False
  return True

n,m=map(int,input().split())
edge=[[] for _ in range(n)]
redge=[[] for _ in range(n)]
edges=[[-1]*n for _ in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  redge[b].append(a)
  edge[a].append(b)
  edges[a][b]=i

if bipartite_graph_check(n,edge):
  exit(print(-1))
label,_=scc(n,edge)
if label!=1:
  exit(print(-1))

rg="RG"
print("".join([rg[randint(0,1)] for i in range(m)]))
0