結果

問題 No.1254 補強への架け橋
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-29 12:55:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 855 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 75,776 KB
最終ジャッジ日時 2025-01-01 22:10:52
合計ジャッジ時間 32,332 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 123
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
def construct(G, N):
    P = [0]*N
    G0 = [[] for i in range(N)]
    V = []

    lb = [0]*N
    def dfs(v, p):
        P[v] = p
        V.append(v)
        lb[v] = len(V)
        for w in G[v]:
            if w == p:
                continue
            if lb[w]:
                if lb[v] < lb[w]:
                    G0[v].append(w)
                continue
            dfs(w, v)
    dfs(0, -1)

    B = []
    ap = [0]*N

    used = [0]*N
    first = 1
    used[0] = 1
    for u in V:
        if not used[u]:
            p = P[u]
            B.append((u, p) if u < p else (p, u))
            if len(G[u]) > 1:
                ap[u] = 1
            if len(G[p]) > 1:
                ap[p] = 1

        cycle = 0
        for v in G0[u]:
            w = v
            while w != u and not used[w]:
                used[w] = 1
                w = P[w]
            if w == u:
                cycle = 1

        if cycle:
            if not first:
                ap[u] = 1
            first = 0

    A = [v for v in range(N) if ap[v]]
    return B
n=int(input())
g=[[] for _ in range(n)]
bridge=[]
for _ in range(n):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    if a>b:
        a,b=b,a
    bridge.append((a-1,b-1))
l=construct(g,n)
l=set(l)
ans=[]
for i in range(n):
    if bridge[i] not in l:
        ans.append(i+1)
print(len(ans))
print(*ans)
0