結果

問題 No.1640 簡単な色塗り
ユーザー googol_S0googol_S0
提出日時 2021-08-06 21:33:04
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,572 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 898,628 KB
最終ジャッジ日時 2023-09-12 01:41:44
合計ジャッジ時間 36,189 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,592 KB
testcase_01 MLE -
testcase_02 AC 71 ms
71,560 KB
testcase_03 AC 72 ms
71,260 KB
testcase_04 AC 844 ms
291,204 KB
testcase_05 TLE -
testcase_06 AC 455 ms
71,440 KB
testcase_07 AC 72 ms
71,564 KB
testcase_08 AC 70 ms
71,380 KB
testcase_09 AC 72 ms
71,380 KB
testcase_10 AC 1,066 ms
247,036 KB
testcase_11 AC 972 ms
217,576 KB
testcase_12 AC 794 ms
209,244 KB
testcase_13 AC 1,566 ms
310,500 KB
testcase_14 AC 1,634 ms
332,784 KB
testcase_15 AC 761 ms
188,968 KB
testcase_16 AC 754 ms
197,564 KB
testcase_17 AC 1,273 ms
276,304 KB
testcase_18 AC 239 ms
96,152 KB
testcase_19 AC 994 ms
227,884 KB
testcase_20 AC 984 ms
254,408 KB
testcase_21 AC 835 ms
214,488 KB
testcase_22 AC 261 ms
93,928 KB
testcase_23 AC 1,251 ms
277,160 KB
testcase_24 AC 387 ms
130,604 KB
testcase_25 AC 838 ms
211,692 KB
testcase_26 AC 1,587 ms
322,604 KB
testcase_27 AC 764 ms
191,200 KB
testcase_28 AC 1,509 ms
316,128 KB
testcase_29 AC 1,227 ms
276,260 KB
testcase_30 MLE -
testcase_31 MLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
07_evil_01.txt -- -
07_evil_02.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.buffer.readline
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  for j in range(2):
    X[i][j]-=1
Q=[[] for i in range(N)]
for i in range(N):
  for j in range(2):
    Q[X[i][j]].append(j*N+i)
G=[[] for i in range(N*6)]
v,w=0,0
for i in range(N):
  w+=len(Q[i])
  for j in range(len(Q[i])):
    if j:
      G[(N+Q[i][j])%(2*N)].append(2*N+(v+j-1)*2)
    if j+1!=len(Q[i]):
      G[(N+Q[i][j])%(2*N)].append(2*N+(v+j+1)*2+1)
    G[2*N+(v+j)*2].append(Q[i][j])
    G[2*N+(v+j)*2+1].append(Q[i][j])
  for j in range(v,w):
    if j!=v:
      G[2*N+j*2].append(2*N+(j-1)*2)
    if j+1!=w:
      G[2*N+j*2+1].append(2*N+(j+1)*2+1)
  v=w
sys.setrecursionlimit(10**7)
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(len(G)):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

C=[0]*len(G)
G=SCC(G)
for i in range(len(G)):
  for j in range(len(G[i])):
    C[G[i][j]]=i
ANS=[0]*N
for i in range(N):
  if C[i]==C[i+N]:
    print('No')
    exit()
  if C[i]<C[i+N]:
    ANS[i]=X[i][0]+1
  else:
    ANS[i]=X[i][1]+1
print('Yes')
print(*ANS,sep='\n')
0