結果

問題 No.1254 補強への架け橋
ユーザー H3PO4H3PO4
提出日時 2020-10-09 23:04:56
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,337 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 86,644 KB
実行使用メモリ 112,236 KB
最終ジャッジ日時 2023-09-27 19:26:20
合計ジャッジ時間 26,657 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,208 KB
testcase_01 AC 65 ms
71,132 KB
testcase_02 AC 64 ms
70,776 KB
testcase_03 AC 66 ms
71,060 KB
testcase_04 AC 64 ms
70,888 KB
testcase_05 AC 63 ms
70,944 KB
testcase_06 AC 67 ms
71,056 KB
testcase_07 AC 64 ms
71,060 KB
testcase_08 AC 65 ms
71,136 KB
testcase_09 AC 65 ms
70,888 KB
testcase_10 AC 65 ms
70,944 KB
testcase_11 AC 65 ms
71,116 KB
testcase_12 AC 65 ms
70,892 KB
testcase_13 AC 63 ms
71,132 KB
testcase_14 AC 64 ms
70,952 KB
testcase_15 AC 64 ms
71,252 KB
testcase_16 AC 63 ms
71,208 KB
testcase_17 AC 64 ms
71,068 KB
testcase_18 AC 64 ms
70,984 KB
testcase_19 AC 66 ms
71,116 KB
testcase_20 AC 67 ms
71,200 KB
testcase_21 AC 67 ms
71,124 KB
testcase_22 AC 65 ms
71,140 KB
testcase_23 AC 65 ms
71,236 KB
testcase_24 AC 64 ms
71,292 KB
testcase_25 AC 68 ms
71,252 KB
testcase_26 AC 66 ms
71,124 KB
testcase_27 AC 65 ms
71,168 KB
testcase_28 AC 64 ms
71,160 KB
testcase_29 AC 64 ms
70,944 KB
testcase_30 AC 66 ms
71,200 KB
testcase_31 AC 64 ms
71,292 KB
testcase_32 AC 65 ms
71,204 KB
testcase_33 AC 66 ms
71,324 KB
testcase_34 AC 67 ms
71,252 KB
testcase_35 AC 64 ms
71,240 KB
testcase_36 AC 65 ms
71,056 KB
testcase_37 AC 64 ms
71,196 KB
testcase_38 AC 67 ms
71,044 KB
testcase_39 AC 65 ms
70,956 KB
testcase_40 AC 64 ms
71,160 KB
testcase_41 AC 65 ms
71,108 KB
testcase_42 AC 65 ms
71,092 KB
testcase_43 AC 76 ms
76,248 KB
testcase_44 AC 74 ms
75,060 KB
testcase_45 AC 67 ms
71,256 KB
testcase_46 AC 76 ms
76,268 KB
testcase_47 AC 70 ms
74,916 KB
testcase_48 AC 81 ms
76,356 KB
testcase_49 AC 68 ms
71,148 KB
testcase_50 AC 81 ms
76,156 KB
testcase_51 AC 79 ms
76,160 KB
testcase_52 AC 84 ms
76,556 KB
testcase_53 AC 78 ms
76,312 KB
testcase_54 AC 84 ms
76,380 KB
testcase_55 AC 76 ms
76,292 KB
testcase_56 AC 66 ms
71,088 KB
testcase_57 AC 72 ms
75,228 KB
testcase_58 AC 72 ms
75,296 KB
testcase_59 AC 66 ms
70,980 KB
testcase_60 AC 67 ms
71,216 KB
testcase_61 AC 78 ms
76,320 KB
testcase_62 AC 69 ms
71,244 KB
testcase_63 AC 136 ms
81,644 KB
testcase_64 AC 106 ms
78,460 KB
testcase_65 AC 127 ms
80,392 KB
testcase_66 AC 126 ms
78,940 KB
testcase_67 AC 101 ms
78,056 KB
testcase_68 AC 122 ms
79,096 KB
testcase_69 AC 128 ms
80,192 KB
testcase_70 AC 112 ms
78,732 KB
testcase_71 AC 101 ms
78,256 KB
testcase_72 AC 126 ms
80,664 KB
testcase_73 AC 108 ms
78,036 KB
testcase_74 AC 122 ms
80,128 KB
testcase_75 AC 123 ms
78,976 KB
testcase_76 AC 91 ms
76,692 KB
testcase_77 AC 121 ms
79,052 KB
testcase_78 AC 141 ms
81,140 KB
testcase_79 AC 130 ms
80,888 KB
testcase_80 AC 125 ms
80,176 KB
testcase_81 AC 130 ms
80,368 KB
testcase_82 AC 127 ms
80,200 KB
testcase_83 AC 370 ms
112,088 KB
testcase_84 AC 362 ms
109,204 KB
testcase_85 AC 272 ms
99,092 KB
testcase_86 AC 331 ms
104,768 KB
testcase_87 AC 360 ms
108,252 KB
testcase_88 AC 153 ms
83,068 KB
testcase_89 AC 368 ms
110,756 KB
testcase_90 AC 271 ms
100,044 KB
testcase_91 AC 248 ms
96,308 KB
testcase_92 AC 167 ms
87,980 KB
testcase_93 AC 310 ms
104,296 KB
testcase_94 AC 297 ms
101,680 KB
testcase_95 AC 290 ms
101,648 KB
testcase_96 AC 342 ms
109,160 KB
testcase_97 AC 210 ms
92,724 KB
testcase_98 AC 363 ms
108,484 KB
testcase_99 AC 250 ms
98,460 KB
testcase_100 AC 368 ms
112,236 KB
testcase_101 AC 176 ms
86,740 KB
testcase_102 AC 137 ms
81,832 KB
testcase_103 AC 174 ms
86,856 KB
testcase_104 AC 221 ms
90,140 KB
testcase_105 AC 317 ms
103,732 KB
testcase_106 AC 224 ms
93,748 KB
testcase_107 AC 367 ms
110,508 KB
testcase_108 AC 355 ms
110,432 KB
testcase_109 AC 306 ms
103,148 KB
testcase_110 AC 300 ms
102,804 KB
testcase_111 AC 303 ms
102,720 KB
testcase_112 AC 194 ms
89,456 KB
testcase_113 AC 302 ms
101,580 KB
testcase_114 AC 227 ms
92,832 KB
testcase_115 AC 157 ms
83,844 KB
testcase_116 AC 246 ms
96,652 KB
testcase_117 AC 196 ms
90,320 KB
testcase_118 AC 368 ms
108,656 KB
testcase_119 AC 257 ms
97,608 KB
testcase_120 AC 335 ms
107,344 KB
testcase_121 AC 177 ms
87,576 KB
testcase_122 AC 242 ms
95,912 KB
testcase_123 AC 65 ms
71,168 KB
testcase_124 RE -
testcase_125 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline
int1 = lambda x: int(x) - 1


def bridge(G, N):
    """
    橋検出
    https://tjkendev.github.io/procon-library/python/graph/bridge.html より拝借しています。
    networkxが使えないサイト用
    """
    result = set()
    label = [None] * N
    gen = 0
    cost = [0] * N

    def dfs(u, p):
        nonlocal gen
        res = 0
        for v in G[u]:
            if v == p:
                continue
            if label[v] is not None:
                if label[v] < label[u]:
                    cost[v] += 1
                    res += 1
            else:
                label[v] = gen
                gen += 1
                r = dfs(v, u)
                if r == 0:
                    result.add((u, v) if u < v else (v, u))
                res += r
        res -= cost[u]
        return res

    for v in range(N):
        if not label[v]:
            label[v] = gen
            gen += 1
            r = dfs(v, -1)
            # assert r == 0, r
    return result


N = int(input())
G = [[] for _ in range(N)]
AB = [tuple(sorted(list(map(int1, input().split())))) for _ in range(N)]
for a, b in AB:
    G[a].append(b)
    G[b].append(a)

res = bridge(G, N)
ans = []
for i in range(N):
    if AB[i] not in res:
        ans.append(i + 1)
print(len(ans))
print(*ans)
0