結果

問題 No.1254 補強への架け橋
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-10 01:42:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 535 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 203,912 KB
最終ジャッジ日時 2023-09-27 20:48:35
合計ジャッジ時間 26,686 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,052 KB
testcase_01 AC 65 ms
71,104 KB
testcase_02 AC 61 ms
71,352 KB
testcase_03 AC 62 ms
71,152 KB
testcase_04 AC 64 ms
71,296 KB
testcase_05 AC 64 ms
70,916 KB
testcase_06 AC 66 ms
71,024 KB
testcase_07 AC 64 ms
71,332 KB
testcase_08 AC 61 ms
71,120 KB
testcase_09 AC 63 ms
71,244 KB
testcase_10 AC 62 ms
71,248 KB
testcase_11 AC 64 ms
71,232 KB
testcase_12 AC 63 ms
71,120 KB
testcase_13 AC 63 ms
71,296 KB
testcase_14 AC 64 ms
71,236 KB
testcase_15 AC 65 ms
71,372 KB
testcase_16 AC 69 ms
71,052 KB
testcase_17 AC 66 ms
71,424 KB
testcase_18 AC 63 ms
71,300 KB
testcase_19 AC 62 ms
71,052 KB
testcase_20 AC 63 ms
71,236 KB
testcase_21 AC 62 ms
71,316 KB
testcase_22 AC 64 ms
71,388 KB
testcase_23 AC 64 ms
71,292 KB
testcase_24 AC 64 ms
71,120 KB
testcase_25 AC 62 ms
71,288 KB
testcase_26 AC 61 ms
71,176 KB
testcase_27 AC 62 ms
71,164 KB
testcase_28 AC 63 ms
71,244 KB
testcase_29 AC 66 ms
71,424 KB
testcase_30 AC 63 ms
71,152 KB
testcase_31 AC 64 ms
71,324 KB
testcase_32 AC 64 ms
71,060 KB
testcase_33 AC 63 ms
71,176 KB
testcase_34 AC 67 ms
71,364 KB
testcase_35 AC 64 ms
71,128 KB
testcase_36 AC 62 ms
71,332 KB
testcase_37 AC 63 ms
71,396 KB
testcase_38 AC 66 ms
70,916 KB
testcase_39 AC 64 ms
71,424 KB
testcase_40 AC 66 ms
71,328 KB
testcase_41 AC 65 ms
71,248 KB
testcase_42 AC 61 ms
71,056 KB
testcase_43 AC 73 ms
75,216 KB
testcase_44 AC 66 ms
70,916 KB
testcase_45 AC 66 ms
71,028 KB
testcase_46 AC 74 ms
75,732 KB
testcase_47 AC 66 ms
71,244 KB
testcase_48 AC 69 ms
74,964 KB
testcase_49 AC 65 ms
71,328 KB
testcase_50 AC 71 ms
75,928 KB
testcase_51 AC 70 ms
75,584 KB
testcase_52 AC 73 ms
75,792 KB
testcase_53 AC 70 ms
75,020 KB
testcase_54 AC 72 ms
75,860 KB
testcase_55 AC 71 ms
75,880 KB
testcase_56 AC 65 ms
70,924 KB
testcase_57 AC 76 ms
76,020 KB
testcase_58 AC 74 ms
75,704 KB
testcase_59 AC 63 ms
71,360 KB
testcase_60 AC 65 ms
71,152 KB
testcase_61 AC 71 ms
74,836 KB
testcase_62 AC 63 ms
70,916 KB
testcase_63 AC 140 ms
80,324 KB
testcase_64 AC 112 ms
78,928 KB
testcase_65 AC 132 ms
79,424 KB
testcase_66 AC 120 ms
79,324 KB
testcase_67 AC 97 ms
78,328 KB
testcase_68 AC 131 ms
79,740 KB
testcase_69 AC 132 ms
79,900 KB
testcase_70 AC 106 ms
78,656 KB
testcase_71 AC 101 ms
78,232 KB
testcase_72 AC 137 ms
79,896 KB
testcase_73 AC 108 ms
78,352 KB
testcase_74 AC 132 ms
80,036 KB
testcase_75 AC 125 ms
79,380 KB
testcase_76 AC 82 ms
76,964 KB
testcase_77 AC 123 ms
78,952 KB
testcase_78 AC 139 ms
80,256 KB
testcase_79 AC 133 ms
80,304 KB
testcase_80 AC 129 ms
80,528 KB
testcase_81 AC 144 ms
80,296 KB
testcase_82 AC 137 ms
80,364 KB
testcase_83 AC 301 ms
99,956 KB
testcase_84 AC 306 ms
98,528 KB
testcase_85 AC 241 ms
91,444 KB
testcase_86 AC 275 ms
96,780 KB
testcase_87 AC 278 ms
97,252 KB
testcase_88 AC 150 ms
81,612 KB
testcase_89 AC 321 ms
100,304 KB
testcase_90 AC 247 ms
92,756 KB
testcase_91 AC 208 ms
89,872 KB
testcase_92 AC 174 ms
84,000 KB
testcase_93 AC 268 ms
95,616 KB
testcase_94 AC 264 ms
93,528 KB
testcase_95 AC 253 ms
94,312 KB
testcase_96 AC 324 ms
98,224 KB
testcase_97 AC 204 ms
88,016 KB
testcase_98 AC 315 ms
98,364 KB
testcase_99 AC 237 ms
90,856 KB
testcase_100 AC 316 ms
100,440 KB
testcase_101 AC 177 ms
83,492 KB
testcase_102 AC 144 ms
80,724 KB
testcase_103 AC 175 ms
83,976 KB
testcase_104 AC 193 ms
86,388 KB
testcase_105 AC 266 ms
96,420 KB
testcase_106 AC 219 ms
89,172 KB
testcase_107 AC 301 ms
99,528 KB
testcase_108 AC 301 ms
99,516 KB
testcase_109 AC 277 ms
95,356 KB
testcase_110 AC 247 ms
93,536 KB
testcase_111 AC 250 ms
94,496 KB
testcase_112 AC 197 ms
85,504 KB
testcase_113 AC 263 ms
93,760 KB
testcase_114 AC 213 ms
88,620 KB
testcase_115 AC 169 ms
82,172 KB
testcase_116 AC 219 ms
89,996 KB
testcase_117 AC 186 ms
85,912 KB
testcase_118 AC 300 ms
98,096 KB
testcase_119 AC 235 ms
90,476 KB
testcase_120 AC 297 ms
97,632 KB
testcase_121 AC 181 ms
85,184 KB
testcase_122 AC 218 ms
89,496 KB
testcase_123 AC 63 ms
71,384 KB
testcase_124 AC 535 ms
203,912 KB
testcase_125 AC 523 ms
201,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1254

強連結成分分解っぽいが違う
とりあえず全域木をとってみる

木に入っていない辺は不要な辺であることは確定
後、木に辺を置いたときにそのパス上にある辺は不要
→どのパスの上にもない辺を求めればいい
→ハッシュでXorしていけばできそうな気もしちゃうが…
あ、N本かよ

"""

from sys import stdin
import sys
sys.setrecursionlimit(200000)

def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
        elif rank[ap] < rank[bp]:
            p[ap] = bp
        else:
            p[bp] = ap
            rank[ap] += 1

        return False

def dfs(v,p):
    ret = 0
    if v == end:
        ret = 1
    for nex,ind in lis[v]:
        if nex != p and ind != unuse:
            now = dfs(nex,v)
            if now == 1:
                ans.append(ind+1)
            ret |= now
    return ret

N = int(stdin.readline())

lis = [ [] for i in range(N) ]
ab = []

for i in range(N):
    a,b = map(int,stdin.readline().split())
    a -= 1
    b -= 1
    lis[a].append((b,i))
    lis[b].append((a,i))
    ab.append((a,b))

#まず、最小全域木を構成して、不要な辺を1つ見つける

p = [i for i in range(N)]
rank = [0] * N

unuse = None
for i in range(N):
    a,b = ab[i]
    if uf_union(a,b,p,rank):
        unuse = i

start,end = ab[unuse]
ans = [unuse+1]
dfs(start,start)

print (len(ans))
print (*ans)
    
    



0