結果

問題 No.2301 Namorientation
ユーザー titiatitia
提出日時 2023-05-12 23:04:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 984 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 106,260 KB
最終ジャッジ日時 2023-08-19 05:57:11
合計ジャッジ時間 27,247 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 14 ms
8,180 KB
testcase_09 WA -
testcase_10 AC 14 ms
8,212 KB
testcase_11 AC 14 ms
8,308 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 740 ms
104,044 KB
testcase_23 AC 723 ms
102,284 KB
testcase_24 AC 604 ms
86,832 KB
testcase_25 AC 588 ms
82,352 KB
testcase_26 AC 816 ms
104,504 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
EDGE=[list(map(int,input().split())) for i in range(N)]

E=[[] for i in range(N+1)]
DEG=[0]*(N+1)

for i in range(N):
    a,b=EDGE[i]

    E[a].append((b,0,i))
    E[b].append((a,1,i))

    DEG[a]+=1
    DEG[b]+=1

ANS=[""]*N

Q=[]
for i in range(1,N+1):
    if DEG[i]==1:
        Q.append(i)

while Q:
    x=Q.pop()

    for to ,com, ind in E[x]:
        DEG[to]-=1
        
        if com==0:
            ANS[ind]="->"
        else:
            ANS[ind]="<-"

        if DEG[to]==1:
            Q.append(to)

USE=[0]*(N+1)

for i in range(1,N+1):
    if DEG[i]==2:
        now=i
    else:
        USE[i]=1

initial = now

while USE[now]==0:
    #print("!",now)
    USE[now]=1
    for to ,com, ind in E[now]:
        if USE[to]==0 or to==initial:

            if com==0:
                ANS[ind]="->"
            else:
                ANS[ind]="<-"

            now=to
            break

for ans in ANS:
    print(ans)


    



0