結果

問題 No.3086 Re One Two
ユーザー Cecil
提出日時 2025-04-05 01:00:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 123,796 KB
最終ジャッジ日時 2025-04-05 01:01:10
合計ジャッジ時間 11,270 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
N = int(input())
A = list()
B = list()
for _ in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
B1 = list()
for i in range(N):
    if B[i]==1:
        B1.append(i)
ab = [[] for _ in range(N)]
indeg = [0 for _ in range(N)]
for i in range(N):
    if A[i]==1:
        ab[i+1].append(i)
        indeg[i] += 1
    if B[i]==2:
        idx = bisect_left(B1,i)
        if idx<len(B1):
            ab[B1[idx]].append(i)
            indeg[i] += 1
ans = []
for i in range(N):
    if indeg[i]>0:
        continue
    now = i
    while True:
        ans.append(now)
        if not ab[now]:
            break
        now = ab[now][0]
for i in range(N):
    print(ans[i]+1)
0