結果
| 問題 |
No.2301 Namorientation
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2023-05-12 23:10:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,649 ms / 3,000 ms |
| コード長 | 1,184 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 110,208 KB |
| 最終ジャッジ日時 | 2024-11-28 19:53:38 |
| 合計ジャッジ時間 | 33,059 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
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)
titia