結果
| 問題 |
No.3056 Disconnected Coloring
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-03-14 21:52:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,058 bytes |
| コンパイル時間 | 2,045 ms |
| コンパイル使用メモリ | 82,624 KB |
| 実行使用メモリ | 152,344 KB |
| 最終ジャッジ日時 | 2025-03-14 21:52:58 |
| 合計ジャッジ時間 | 19,018 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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("".join(ANS))
exit()
ANS=["R"]*M
NOW=0
Q=[N-1]
USE=[0]*N
USE[N-1]=1
while Q:
x=Q.pop()
for to,ind in E[x]:
if to==0:
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("".join(ANS))
exit()
print(-1)
titia