結果

問題 No.3056 Disconnected Coloring
ユーザー titia
提出日時 2025-03-14 22:31:59
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 2,337 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 137,792 KB
最終ジャッジ日時 2025-03-14 22:32:49
合計ジャッジ時間 40,947 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 1
other AC * 19 RE * 13 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
input = sys.stdin.readline
from collections import deque
def calc(ANS,EDGE):
USE=[0]*M
E=[[] for i in range(N)]
for i in range(M):
if ANS[i]=="R":
x,y=EDGE[i]
E[x].append(y)
E[y].append(x)
Q=deque()
Q.append(0)
USE=[0]*N
USE[0]=1
while Q:
x=Q.popleft()
for to in E[x]:
if USE[to]==0:
USE[to]=1
Q.append(to)
if USE[N-1]==1:
return False
E=[[] for i in range(N)]
for i in range(M):
if ANS[i]=="B":
x,y=EDGE[i]
E[x].append(y)
E[y].append(x)
Q=deque()
Q.append(0)
USE=[0]*N
USE[0]=1
while Q:
x=Q.popleft()
for to in E[x]:
if USE[to]==0:
USE[to]=1
Q.append(to)
if USE[N-1]==1:
return False
return True
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
E=[[] for i in range(N)]
for i in range(M):
x,y=EDGE[i]
if x==0 and y==N-1:
print(-1)
exit()
if x==N-1 and y==0:
print(-1)
exit()
E[x].append((y,i))
E[y].append((x,i))
if len(E[0])<=M//2:
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")==ANS.count("B"):
print("".join(ANS))
assert calc(ANS,EDGE)==True
exit()
if len(E[N-1])<=M//2:
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")==ANS.count("B"):
print("".join(ANS))
assert calc(ANS,EDGE)==True
exit()
XXX=[i for i in range(1<<(1<<20000))]
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0