結果

問題 No.3056 Disconnected Coloring
ユーザー ゼット
提出日時 2025-03-14 21:39:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 124,264 KB
最終ジャッジ日時 2025-03-14 21:39:45
合計ジャッジ時間 16,223 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
G=[[] for i in range(N+1)]
if M%2==1:
  print(-1)
  exit()
for i in range(M):
  x,y=map(int,input().split())
  if x>y:
    x,y=y,x
  if x==1 and y==N:
    print(-1)
    exit()
  G[y].append((x,i))
  G[x].append((y,i))
c=0
result=['B']*M
if len(G[1])<=M//2:
  for B in G[1]:
    y,pos=B[:]
    result[pos]='R'
    c+=1
else:
  for B in G[y]:
    y,pos=B[:]
    result[pos]='R'
for x in range(1,N+1):
  if c==M//2:
    break
  for B in G[x]:
    y,pos=B[:]
    if result[pos]=='R':
      continue
    result[pos]='R'
    c+=1
    if c==M//2:
      break
print(*result,sep='')
    
0