結果

問題 No.2301 Namorientation
ユーザー ああいいああいい
提出日時 2023-05-12 22:36:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 744 ms / 3,000 ms
コード長 1,227 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 183,028 KB
最終ジャッジ日時 2024-05-06 12:41:10
合計ジャッジ時間 18,483 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 36 ms
52,352 KB
testcase_02 AC 38 ms
51,968 KB
testcase_03 AC 36 ms
52,224 KB
testcase_04 AC 35 ms
52,352 KB
testcase_05 AC 37 ms
52,352 KB
testcase_06 AC 36 ms
51,968 KB
testcase_07 AC 36 ms
52,096 KB
testcase_08 AC 35 ms
51,840 KB
testcase_09 AC 37 ms
51,968 KB
testcase_10 AC 36 ms
52,224 KB
testcase_11 AC 40 ms
52,096 KB
testcase_12 AC 438 ms
123,600 KB
testcase_13 AC 408 ms
120,648 KB
testcase_14 AC 717 ms
164,416 KB
testcase_15 AC 486 ms
133,488 KB
testcase_16 AC 609 ms
146,588 KB
testcase_17 AC 449 ms
126,764 KB
testcase_18 AC 669 ms
143,424 KB
testcase_19 AC 368 ms
117,564 KB
testcase_20 AC 605 ms
149,600 KB
testcase_21 AC 495 ms
132,192 KB
testcase_22 AC 387 ms
154,692 KB
testcase_23 AC 408 ms
160,564 KB
testcase_24 AC 335 ms
141,100 KB
testcase_25 AC 325 ms
144,760 KB
testcase_26 AC 411 ms
183,028 KB
testcase_27 AC 719 ms
157,808 KB
testcase_28 AC 727 ms
157,412 KB
testcase_29 AC 744 ms
157,412 KB
testcase_30 AC 730 ms
158,564 KB
testcase_31 AC 728 ms
157,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
d = dict()
G = [[] for _ in range(N + 1)]
Gnum = [0] * N
for _ in range(N):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    d[(a,b)] = _
    Gnum[a] += 1
    Gnum[b] += 1

stack = []
for i in range(N):
    if Gnum[i] == 1:
        stack.append(i)
ans = [0] * N
right = "->"
left = "<-"

s = set()
while stack:
    now = stack.pop()
    s.add(now)
    for v in G[now]:
        Gnum[v] -= 1
        if Gnum[v] == 1:
            stack.append(v)
        if Gnum[v] <= 0:continue
        if (now,v) in d:
            ans[d[(now,v)]] = right
        else:
            ans[d[(v,now)]] = left
t = -1
for i in range(N):
    if i not in s:
        t = i
        break
if t == -1:
    pass
else:
    u = t
    flag = True
    s.add(t)
    while flag:
        flag = False
        for v in G[u]:
            if v not in s:
                flag = True
                if (u,v) in d:
                    ans[d[(u,v)]] = right
                else:
                    ans[d[(v,u)]] = left
                s.add(v)
                u = v
                break
    if (u,t) in d:
        ans[d[(u,t)]] = right
    else:
        ans[d[(t,u)]] = left
for S in ans:
    print(S)
0