結果
| 問題 |
No.2301 Namorientation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-12 22:24:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 797 ms / 3,000 ms |
| コード長 | 1,068 bytes |
| コンパイル時間 | 198 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 173,316 KB |
| 最終ジャッジ日時 | 2024-11-28 18:53:41 |
| 合計ジャッジ時間 | 19,725 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
n = int(input())
edges = [[int(x)-1 for x in input().split()] for i in range(n)]
e = [[] for i in range(n)]
for ind,(a,b) in enumerate(edges):
e[a].append([b,ind])
e[b].append([a,ind])
ans = [-1]*n
num = [0]*n
for a,b in edges:
num[a] += 1
num[b] += 1
q = []
vis = [0]*n
for i in range(n):
if num[i] == 1:
q.append(i)
while q:
now = q.pop()
vis[now] = 1
for nex,ind in e[now]:
if ans[ind] != -1:
continue
num[nex] -= 1
if edges[ind][0] == now:
ans[ind] = 0
else:
ans[ind] = 1
if num[nex] == 1:
q.append(nex)
is_cycle = [0]*n
for i in range(n):
if vis[i] == 0:
q = [i]
is_cycle[i] = 1
break
while q:
now = q.pop()
for nex,ind in e[now]:
if ans[ind] != -1:
continue
if edges[ind][0] == now:
ans[ind] = 0
else:
ans[ind] = 1
vis[nex] = 1
q.append(nex)
break
for i in ans:
print("<-" if i else "->")