結果

問題 No.2301 Namorientation
ユーザー 👑 timitimi
提出日時 2023-05-13 18:18:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 848 ms / 3,000 ms
コード長 1,376 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 225,908 KB
最終ジャッジ日時 2024-05-06 23:15:58
合計ジャッジ時間 20,360 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,016 KB
testcase_01 AC 42 ms
54,016 KB
testcase_02 AC 44 ms
54,016 KB
testcase_03 AC 42 ms
54,400 KB
testcase_04 AC 40 ms
54,400 KB
testcase_05 AC 40 ms
54,144 KB
testcase_06 AC 39 ms
54,144 KB
testcase_07 AC 43 ms
54,144 KB
testcase_08 AC 40 ms
53,888 KB
testcase_09 AC 41 ms
54,144 KB
testcase_10 AC 40 ms
54,144 KB
testcase_11 AC 41 ms
54,016 KB
testcase_12 AC 498 ms
160,944 KB
testcase_13 AC 438 ms
150,368 KB
testcase_14 AC 844 ms
217,476 KB
testcase_15 AC 586 ms
169,032 KB
testcase_16 AC 727 ms
200,488 KB
testcase_17 AC 518 ms
163,368 KB
testcase_18 AC 717 ms
203,696 KB
testcase_19 AC 425 ms
146,884 KB
testcase_20 AC 690 ms
198,176 KB
testcase_21 AC 532 ms
166,920 KB
testcase_22 AC 435 ms
207,896 KB
testcase_23 AC 421 ms
208,660 KB
testcase_24 AC 350 ms
185,244 KB
testcase_25 AC 361 ms
184,104 KB
testcase_26 AC 445 ms
225,908 KB
testcase_27 AC 836 ms
218,396 KB
testcase_28 AC 802 ms
218,656 KB
testcase_29 AC 827 ms
218,008 KB
testcase_30 AC 848 ms
218,524 KB
testcase_31 AC 838 ms
217,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
D=[0]*N;DD=[[] for _ in range(N)]
A=[];B=[]
for i in range(N):
  u,v=map(int,input().split())
  u-=1;v-=1
  A.append((u,v))
  D[u]+=1;D[v]+=1 
  DD[u].append((v,i))
  DD[v].append((u,i))
V=[-1]*N
#print(D)
from collections import deque
d=deque()
for i in range(N):
  if D[i]==1:
    d.append(i)

while d:
  now=d.popleft()
  for nex,i in DD[now]:
    if V[nex]==1:
      continue
    B.append((now,nex))
    D[now]-=1;D[nex]-=1
    V[now]=1
    if D[nex]==1:
      d.append(nex)
      
#print(B)
F=[[] for i in range(N)]
for u,v in B:
  F[u].append(v)
for i in range(N):
  F[i]=set(F[i])

ans=[0]*N
for i in range(N):
  u,v=A[i]
  if v in F[u]:
    ans[i]=1 
  if u in F[v]:
    ans[i]=-1 
d=deque();f=0;V=[1]*N
for i in range(N):
  if D[i]==2 and f==0:
    g=i;f=1
  if D[i]==2:
    V[i]=-1 


for nex,i in DD[g]:
  if V[nex]==-1:
    s=nex
    break
#print(V,s,g,DD)
FF=[[] for i in range(N)]
FF[g].append(s)
#print('FF',FF)
d.append(s)
#print(d,s,g)
while d:
  now=d.popleft()
  #print(now,DD[now])
  for nex,i in DD[now]:
    if now==s and nex==g:
      continue 
    if V[nex]==-1:
      V[now]=1
      FF[now].append(nex)
      d.append(nex)

for i in range(N):
  FF[i]=set(FF[i])
for i in range(N):
  if ans[i]==0:
    u,v=A[i]
    if u in FF[v]:
      ans[i]=1
    else:
      ans[i]=-1 
for i in ans:
  if i==-1:
    print('<-')
  else:
    print('->')
0