結果

問題 No.2301 Namorientation
ユーザー titiatitia
提出日時 2023-05-12 23:10:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,467 ms / 3,000 ms
コード長 1,184 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 107,728 KB
最終ジャッジ日時 2023-08-19 06:04:42
合計ジャッジ時間 33,134 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,260 KB
testcase_01 AC 17 ms
8,376 KB
testcase_02 AC 16 ms
8,264 KB
testcase_03 AC 16 ms
8,288 KB
testcase_04 AC 16 ms
8,264 KB
testcase_05 AC 16 ms
8,312 KB
testcase_06 AC 16 ms
8,256 KB
testcase_07 AC 16 ms
8,308 KB
testcase_08 AC 16 ms
8,296 KB
testcase_09 AC 16 ms
8,352 KB
testcase_10 AC 16 ms
8,300 KB
testcase_11 AC 16 ms
8,300 KB
testcase_12 AC 902 ms
67,748 KB
testcase_13 AC 766 ms
62,780 KB
testcase_14 AC 1,438 ms
107,100 KB
testcase_15 AC 933 ms
74,380 KB
testcase_16 AC 1,178 ms
93,140 KB
testcase_17 AC 871 ms
70,176 KB
testcase_18 AC 1,256 ms
94,800 KB
testcase_19 AC 672 ms
59,044 KB
testcase_20 AC 1,251 ms
93,992 KB
testcase_21 AC 916 ms
73,232 KB
testcase_22 AC 959 ms
105,408 KB
testcase_23 AC 947 ms
104,096 KB
testcase_24 AC 758 ms
88,200 KB
testcase_25 AC 708 ms
83,704 KB
testcase_26 AC 932 ms
106,196 KB
testcase_27 AC 1,467 ms
107,728 KB
testcase_28 AC 1,440 ms
107,684 KB
testcase_29 AC 1,436 ms
107,452 KB
testcase_30 AC 1,426 ms
107,528 KB
testcase_31 AC 1,450 ms
107,708 KB
権限があれば一括ダウンロードができます

ソースコード

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)

USE=[0]*(N+1)

while Q:
    x=Q.pop()
    USE[x]=1

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

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

#print(ANS)

USE=[0]*(N+1)

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

initial = now

LIST=[]

while USE[now]==0:
    USE[now]=1
    LIST.append(now)
    for to ,com, ind in E[now]:
        if USE[to]==0:
            now=to
            break

for i in range(len(LIST)):
    for to ,com, ind in E[LIST[i]]:
        if to==LIST[i-1]:
            if com==0:
                ANS[ind]="->"
            else:
                ANS[ind]="<-"
            break

            

for ans in ANS:
    print(ans)


    



0