結果

問題 No.2301 Namorientation
ユーザー titiatitia
提出日時 2023-05-12 23:10:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,663 ms / 3,000 ms
コード長 1,184 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 110,336 KB
最終ジャッジ日時 2024-05-06 13:13:32
合計ジャッジ時間 33,893 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 32 ms
10,752 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 31 ms
10,880 KB
testcase_12 AC 970 ms
70,144 KB
testcase_13 AC 844 ms
65,132 KB
testcase_14 AC 1,640 ms
109,696 KB
testcase_15 AC 1,067 ms
76,928 KB
testcase_16 AC 1,366 ms
95,872 KB
testcase_17 AC 1,012 ms
72,576 KB
testcase_18 AC 1,449 ms
97,664 KB
testcase_19 AC 796 ms
61,932 KB
testcase_20 AC 1,426 ms
96,768 KB
testcase_21 AC 1,052 ms
75,904 KB
testcase_22 AC 1,151 ms
108,032 KB
testcase_23 AC 1,127 ms
106,368 KB
testcase_24 AC 960 ms
90,752 KB
testcase_25 AC 821 ms
86,272 KB
testcase_26 AC 1,104 ms
108,928 KB
testcase_27 AC 1,652 ms
110,080 KB
testcase_28 AC 1,641 ms
110,336 KB
testcase_29 AC 1,660 ms
110,208 KB
testcase_30 AC 1,663 ms
110,080 KB
testcase_31 AC 1,641 ms
110,208 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