結果
| 問題 |
No.2301 Namorientation
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2025-10-21 20:40:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,163 ms / 3,000 ms |
| コード長 | 1,009 bytes |
| コンパイル時間 | 451 ms |
| コンパイル使用メモリ | 82,656 KB |
| 実行使用メモリ | 215,976 KB |
| 最終ジャッジ日時 | 2025-10-21 20:40:49 |
| 合計ジャッジ時間 | 25,552 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
def f1(x):
if not E[x]:
return
y, i, d = next(iter(E[x]))
if d == 0:
ans[i] = "->"
else:
ans[i] = "<-"
E[x].remove((y,i,d))
E[y].remove((x,i,d^1))
D[x] -= 1
D[y] -= 1
if D[y] == 1:
NV.remove(y)
Q.append(y)
N = int(input())
AB = []
E = [set() for _ in range(N)]
D = [0] * N
NV = set(range(N))
ans = [""] * N
for i in range(N):
a,b = map(int,input().split())
a -= 1
b -= 1
AB.append((a,b))
E[a].add((b, i, 0))
E[b].add((a, i, 1))
D[a] += 1
D[b] += 1
Q = []
for i in range(N):
if D[i] == 1:
Q.append(i)
NV.remove(i)
while Q:
x = Q.pop()
f1(x)
if NV:
x = next(iter(NV))
Q.append(x)
y,i,d = next(iter(E[x]))
NV.remove(x)
NV.remove(y)
E[x].remove((y, i, d))
E[y].remove((x, i, d ^ 1))
D[x] -= 1
D[y] -= 1
if d == 1:
ans[i] = "->"
else:
ans[i] = "<-"
while Q:
x = Q.pop()
f1(x)
for a in ans:
print(a)
ntuda