結果

問題 No.1254 補強への架け橋
ユーザー KudeKude
提出日時 2020-10-09 23:51:44
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 992 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 87,412 KB
最終ジャッジ日時 2024-07-20 14:43:53
合計ジャッジ時間 34,816 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 123
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

n = int(input())
to = [[] for _ in range(n)]
bmap = {}
for i in range(1, n+1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    bmap[(a, b)] = bmap[(b, a)] = i

num = [-1] * n
low = [-1] * n
visited = [False] * n
ans = 0
nm = 1
def dfs(v, p=-1):
    global nm
    visited[v] = True
    num[v] = nm
    nm += 1
    lw = num[v]
    for w in to[v]:
        if w == p:
            continue
        if not visited[w]:
            dfs(w, v)
            lw = min(lw, low[w])
        else:
            lw = min(lw, num[w])
    low[v] = lw
dfs(0)
ans = set(range(1, n+1))
visited = [False] * n
def dfs2(v, p=-1):
    visited[v] = True
    for w in to[v]:
        if w == p:
            continue
        if not visited[w]:
            dfs2(w, v)
            if low[w] > num[v]:
                ans.remove(bmap[(v, w)])
dfs2(0)
print(len(ans))
print(*ans)
0