結果
問題 |
No.3056 Disconnected Coloring
|
ユーザー |
![]() |
提出日時 | 2025-03-14 21:47:09 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 695 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,724 KB |
実行使用メモリ | 136,280 KB |
最終ジャッジ日時 | 2025-03-14 21:47:30 |
合計ジャッジ時間 | 15,298 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 WA * 14 |
ソースコード
import sys input = sys.stdin.readline N,M=map(int,input().split()) EDGE=[list(map(int,input().split())) for i in range(M)] for i in range(M): EDGE[i][0]-=1 EDGE[i][1]-=1 if M%2==1: print(-1) exit() E=[[] for i in range(N)] for i in range(M): x,y=EDGE[i] E[x].append((y,i)) E[y].append((x,i)) ANS=["R"]*M NOW=0 Q=[0] USE=[0]*N USE[0]=1 while Q: x=Q.pop() for to,ind in E[x]: if to==N-1: continue if ANS[ind]=="R" and NOW<M//2: ANS[ind]="B" if USE[to]==0: Q.append(to) USE[to]=1 NOW+=1 if ANS.count("R")!=M//2: print(-1) else: print("".join(ANS))