結果

問題 No.1254 補強への架け橋
ユーザー 👑 KazunKazun
提出日時 2020-08-10 00:05:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,007 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 139,656 KB
最終ジャッジ日時 2024-04-21 19:30:10
合計ジャッジ時間 42,699 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,760 KB
testcase_01 AC 52 ms
53,632 KB
testcase_02 AC 53 ms
54,016 KB
testcase_03 AC 52 ms
54,016 KB
testcase_04 AC 53 ms
53,888 KB
testcase_05 AC 59 ms
54,400 KB
testcase_06 AC 54 ms
54,400 KB
testcase_07 AC 53 ms
54,144 KB
testcase_08 AC 54 ms
53,888 KB
testcase_09 AC 57 ms
53,760 KB
testcase_10 AC 54 ms
53,760 KB
testcase_11 AC 55 ms
53,632 KB
testcase_12 AC 54 ms
54,272 KB
testcase_13 AC 54 ms
54,400 KB
testcase_14 AC 54 ms
54,656 KB
testcase_15 AC 55 ms
54,144 KB
testcase_16 AC 56 ms
53,760 KB
testcase_17 AC 53 ms
53,888 KB
testcase_18 AC 55 ms
54,016 KB
testcase_19 AC 54 ms
54,400 KB
testcase_20 AC 55 ms
54,272 KB
testcase_21 AC 54 ms
54,528 KB
testcase_22 AC 55 ms
54,016 KB
testcase_23 AC 56 ms
54,016 KB
testcase_24 AC 55 ms
54,144 KB
testcase_25 AC 54 ms
54,144 KB
testcase_26 AC 57 ms
54,400 KB
testcase_27 AC 55 ms
54,656 KB
testcase_28 AC 56 ms
54,528 KB
testcase_29 AC 54 ms
54,272 KB
testcase_30 AC 54 ms
54,144 KB
testcase_31 AC 55 ms
54,528 KB
testcase_32 AC 55 ms
53,632 KB
testcase_33 AC 57 ms
54,400 KB
testcase_34 AC 63 ms
54,272 KB
testcase_35 AC 55 ms
54,528 KB
testcase_36 AC 55 ms
54,528 KB
testcase_37 AC 63 ms
54,272 KB
testcase_38 AC 62 ms
54,528 KB
testcase_39 AC 54 ms
54,144 KB
testcase_40 AC 54 ms
54,272 KB
testcase_41 AC 55 ms
54,400 KB
testcase_42 AC 54 ms
54,272 KB
testcase_43 AC 87 ms
68,480 KB
testcase_44 AC 65 ms
56,320 KB
testcase_45 AC 60 ms
56,064 KB
testcase_46 AC 85 ms
68,096 KB
testcase_47 AC 69 ms
57,088 KB
testcase_48 AC 79 ms
66,432 KB
testcase_49 AC 54 ms
54,528 KB
testcase_50 AC 90 ms
70,016 KB
testcase_51 AC 94 ms
69,888 KB
testcase_52 AC 91 ms
69,376 KB
testcase_53 AC 83 ms
67,584 KB
testcase_54 AC 92 ms
69,120 KB
testcase_55 AC 91 ms
67,712 KB
testcase_56 AC 59 ms
55,040 KB
testcase_57 AC 82 ms
66,816 KB
testcase_58 AC 81 ms
66,432 KB
testcase_59 AC 57 ms
54,528 KB
testcase_60 AC 62 ms
56,064 KB
testcase_61 AC 90 ms
69,120 KB
testcase_62 AC 57 ms
54,784 KB
testcase_63 AC 237 ms
83,840 KB
testcase_64 AC 143 ms
78,336 KB
testcase_65 AC 200 ms
80,640 KB
testcase_66 AC 196 ms
80,256 KB
testcase_67 AC 140 ms
78,080 KB
testcase_68 AC 183 ms
80,256 KB
testcase_69 AC 198 ms
81,280 KB
testcase_70 AC 149 ms
78,080 KB
testcase_71 AC 147 ms
78,720 KB
testcase_72 AC 206 ms
81,280 KB
testcase_73 AC 145 ms
78,592 KB
testcase_74 AC 187 ms
81,408 KB
testcase_75 AC 174 ms
80,384 KB
testcase_76 AC 121 ms
77,568 KB
testcase_77 AC 165 ms
78,976 KB
testcase_78 AC 202 ms
82,816 KB
testcase_79 AC 197 ms
83,072 KB
testcase_80 AC 195 ms
82,048 KB
testcase_81 AC 207 ms
83,048 KB
testcase_82 AC 192 ms
82,176 KB
testcase_83 AC 921 ms
133,776 KB
testcase_84 AC 798 ms
129,316 KB
testcase_85 AC 544 ms
116,880 KB
testcase_86 AC 778 ms
123,204 KB
testcase_87 AC 799 ms
129,500 KB
testcase_88 AC 235 ms
86,272 KB
testcase_89 AC 831 ms
133,880 KB
testcase_90 AC 560 ms
117,492 KB
testcase_91 AC 466 ms
106,896 KB
testcase_92 AC 300 ms
93,952 KB
testcase_93 AC 710 ms
121,772 KB
testcase_94 AC 596 ms
117,788 KB
testcase_95 AC 621 ms
117,812 KB
testcase_96 AC 764 ms
129,596 KB
testcase_97 AC 399 ms
103,500 KB
testcase_98 AC 789 ms
129,576 KB
testcase_99 AC 508 ms
112,964 KB
testcase_100 AC 872 ms
133,400 KB
testcase_101 AC 283 ms
92,800 KB
testcase_102 AC 226 ms
85,376 KB
testcase_103 AC 316 ms
94,080 KB
testcase_104 AC 341 ms
100,072 KB
testcase_105 AC 687 ms
122,460 KB
testcase_106 AC 438 ms
105,540 KB
testcase_107 AC 831 ms
133,612 KB
testcase_108 AC 827 ms
132,740 KB
testcase_109 AC 695 ms
121,660 KB
testcase_110 AC 665 ms
117,764 KB
testcase_111 AC 660 ms
118,516 KB
testcase_112 AC 375 ms
99,864 KB
testcase_113 AC 630 ms
117,512 KB
testcase_114 AC 442 ms
104,408 KB
testcase_115 AC 254 ms
86,784 KB
testcase_116 AC 465 ms
107,020 KB
testcase_117 AC 363 ms
99,652 KB
testcase_118 AC 792 ms
128,928 KB
testcase_119 AC 528 ms
111,196 KB
testcase_120 AC 802 ms
130,296 KB
testcase_121 AC 318 ms
94,464 KB
testcase_122 AC 465 ms
106,860 KB
testcase_123 AC 54 ms
54,144 KB
testcase_124 AC 983 ms
139,492 KB
testcase_125 AC 1,007 ms
139,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N=int(input())
E={v:set() for v in range(1,N+1)}
F={}
G={}

for i in range(N):
    a,b=map(int,input().split())
    E[a].add(b)
    E[b].add(a)

    a,b=min(a,b),max(a,b)
    F[(a,b)]=False
    G[(a,b)]=i+1


T=[False]*(N+1)

S=deque([1])
T[1]=True
while S:
    v=S.pop()
    for u in E[v]:
        if not T[u]:
            S.append(u)
            T[u]=True
            a,b=min(u,v),max(u,v)
            F[(a,b)]=True

p,q=min(F,key=lambda x:F[x])
E[p].remove(q)
E[q].remove(p)

T=[0]*(N+1)
D=[0]*(N+1)
S=deque([p])
T[p]=float("inf")

while S:
    v=S.pop()
    for u in E[v]:
        if not T[u]:
            S.append(u)
            D[u]=D[v]+1
            T[u]=v

H=D[q]
P=[0]*(H+1)
P[0]=q

y=q
i=0
while y!=p:
    i+=1
    y=T[y]
    P[i]=y

X=[G[(p,q)]]+[0]*H
for i in range(H):
    a,b=min(P[i],P[i+1]),max(P[i],P[i+1])
    X[i+1]=G[(a,b)]

X.sort()

print(H+1)
print(" ".join(map(str,X)))
0