結果
| 問題 |
No.2301 Namorientation
|
| コンテスト | |
| ユーザー |
bk_cocoa
|
| 提出日時 | 2023-05-12 22:49:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 782 ms / 3,000 ms |
| コード長 | 1,250 bytes |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 82,264 KB |
| 実行使用メモリ | 170,836 KB |
| 最終ジャッジ日時 | 2024-11-28 19:24:50 |
| 合計ジャッジ時間 | 19,354 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
from collections import deque
N = int(input())
edge_cnt = [0]*N
edge_L = [[] for i in range(N)]
orig_edge_L = []
for i in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
edge_L[a].append(b)
edge_L[b].append(a)
edge_cnt[a] += 1
edge_cnt[b] += 1
orig_edge_L.append([a, b])
que = deque()
for i in range(N):
if edge_cnt[i] == 1:
que.append(i)
used_flg = [False]*N
confirm_edge_s = set()
while que:
now_pos = que.popleft()
used_flg[now_pos] = True
for next_pos in edge_L[now_pos]:
if used_flg[next_pos]:
continue
confirm_edge_s.add((now_pos, next_pos))
edge_cnt[next_pos] -= 1
if edge_cnt[next_pos] == 1:
que.append(next_pos)
for i in range(N):
if used_flg[i] == False:
start_pos = i
que.append(i)
break
while que:
now_pos = que.popleft()
used_flg[now_pos] = True
for next_pos in edge_L[now_pos]:
if used_flg[next_pos]:
continue
que.append(next_pos)
confirm_edge_s.add((now_pos,next_pos))
break
confirm_edge_s.add((now_pos,start_pos))
for a,b in orig_edge_L:
if (a,b) in confirm_edge_s:
print('->')
else:
print('<-')
bk_cocoa