結果

問題 No.2301 Namorientation
ユーザー 👑 rin204rin204
提出日時 2024-03-16 16:04:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 849 ms / 3,000 ms
コード長 1,170 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 155,636 KB
最終ジャッジ日時 2024-03-16 16:05:07
合計ジャッジ時間 23,434 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 45 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 38 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 38 ms
53,460 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 497 ms
110,516 KB
testcase_13 AC 455 ms
108,408 KB
testcase_14 AC 846 ms
142,492 KB
testcase_15 AC 583 ms
117,596 KB
testcase_16 AC 746 ms
129,552 KB
testcase_17 AC 538 ms
111,252 KB
testcase_18 AC 719 ms
128,560 KB
testcase_19 AC 452 ms
106,540 KB
testcase_20 AC 674 ms
129,932 KB
testcase_21 AC 563 ms
117,212 KB
testcase_22 AC 417 ms
147,252 KB
testcase_23 AC 416 ms
146,672 KB
testcase_24 AC 348 ms
131,168 KB
testcase_25 AC 321 ms
133,396 KB
testcase_26 AC 403 ms
155,636 KB
testcase_27 AC 819 ms
140,756 KB
testcase_28 AC 828 ms
140,744 KB
testcase_29 AC 837 ms
140,740 KB
testcase_30 AC 849 ms
140,744 KB
testcase_31 AC 843 ms
140,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
deg = [0] * n
edges = [[] for _ in range(n)]
E = {}
for i in range(n):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    E[(u, v)] = i
    edges[u].append(v)
    edges[v].append(u)
    deg[u] += 1
    deg[v] += 1

ans = [""] * n
st = []
for i in range(n):
    if deg[i] == 1:
        st.append(i)

while st:
    pos = st.pop()
    for npos in edges[pos]:
        if deg[npos] == 0:
            continue

        if (pos, npos) in E:
            ans[E[(pos, npos)]] = "->"
        else:
            ans[E[(npos, pos)]] = "<-"

        deg[pos] -= 1
        deg[npos] -= 1

        if deg[npos] == 1:
            st.append(npos)

u = -1
for i in range(n):
    if deg[i] > 0:
        u = i
        deg[i] -= 1
        break

cycle = [u]
while 1:
    for v in edges[u]:
        if deg[v] > 0:
            cycle.append(v)
            deg[u] -= 1
            deg[v] -= 1
            u = v
            break
    else:
        break

for i in range(len(cycle)):
    pos = cycle[i]
    npos = cycle[(i + 1) % len(cycle)]
    if (pos, npos) in E:
        ans[E[(pos, npos)]] = "->"
    else:
        ans[E[(npos, pos)]] = "<-"

print(*ans, sep="\n")
0