結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 07:35:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 1,965 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 104,872 KB
最終ジャッジ日時 2024-07-20 15:39:15
合計ジャッジ時間 21,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,888 KB
testcase_01 AC 48 ms
53,888 KB
testcase_02 AC 48 ms
53,760 KB
testcase_03 AC 46 ms
54,016 KB
testcase_04 AC 47 ms
53,888 KB
testcase_05 AC 47 ms
53,888 KB
testcase_06 AC 46 ms
53,888 KB
testcase_07 AC 46 ms
54,016 KB
testcase_08 AC 46 ms
54,016 KB
testcase_09 AC 45 ms
53,888 KB
testcase_10 AC 45 ms
54,144 KB
testcase_11 AC 45 ms
54,016 KB
testcase_12 AC 45 ms
53,760 KB
testcase_13 AC 46 ms
54,144 KB
testcase_14 AC 46 ms
54,272 KB
testcase_15 AC 46 ms
54,272 KB
testcase_16 AC 48 ms
54,016 KB
testcase_17 AC 47 ms
54,144 KB
testcase_18 AC 47 ms
54,400 KB
testcase_19 AC 47 ms
53,760 KB
testcase_20 AC 48 ms
54,400 KB
testcase_21 AC 45 ms
53,888 KB
testcase_22 AC 46 ms
53,888 KB
testcase_23 AC 46 ms
54,400 KB
testcase_24 AC 48 ms
54,272 KB
testcase_25 AC 47 ms
54,528 KB
testcase_26 AC 47 ms
54,528 KB
testcase_27 AC 47 ms
54,144 KB
testcase_28 AC 47 ms
54,400 KB
testcase_29 AC 47 ms
54,144 KB
testcase_30 AC 48 ms
53,888 KB
testcase_31 AC 46 ms
54,272 KB
testcase_32 AC 47 ms
54,016 KB
testcase_33 AC 48 ms
54,272 KB
testcase_34 AC 48 ms
54,528 KB
testcase_35 AC 47 ms
54,400 KB
testcase_36 AC 47 ms
54,016 KB
testcase_37 AC 47 ms
54,016 KB
testcase_38 AC 47 ms
54,272 KB
testcase_39 AC 46 ms
54,400 KB
testcase_40 AC 46 ms
54,144 KB
testcase_41 AC 46 ms
54,144 KB
testcase_42 AC 46 ms
53,760 KB
testcase_43 AC 66 ms
64,640 KB
testcase_44 AC 55 ms
61,056 KB
testcase_45 AC 56 ms
61,440 KB
testcase_46 AC 64 ms
64,512 KB
testcase_47 AC 55 ms
61,568 KB
testcase_48 AC 60 ms
63,744 KB
testcase_49 AC 49 ms
54,400 KB
testcase_50 AC 67 ms
65,664 KB
testcase_51 AC 69 ms
66,304 KB
testcase_52 AC 69 ms
66,048 KB
testcase_53 AC 65 ms
64,512 KB
testcase_54 AC 68 ms
66,176 KB
testcase_55 AC 63 ms
64,512 KB
testcase_56 AC 47 ms
54,528 KB
testcase_57 AC 60 ms
63,104 KB
testcase_58 AC 60 ms
63,360 KB
testcase_59 AC 47 ms
54,144 KB
testcase_60 AC 55 ms
60,416 KB
testcase_61 AC 65 ms
64,896 KB
testcase_62 AC 48 ms
54,400 KB
testcase_63 AC 104 ms
78,336 KB
testcase_64 AC 86 ms
72,960 KB
testcase_65 AC 99 ms
77,952 KB
testcase_66 AC 98 ms
77,568 KB
testcase_67 AC 83 ms
71,936 KB
testcase_68 AC 97 ms
77,824 KB
testcase_69 AC 98 ms
77,696 KB
testcase_70 AC 88 ms
73,984 KB
testcase_71 AC 87 ms
74,624 KB
testcase_72 AC 101 ms
77,568 KB
testcase_73 AC 86 ms
74,752 KB
testcase_74 AC 100 ms
77,824 KB
testcase_75 AC 95 ms
77,312 KB
testcase_76 AC 75 ms
69,376 KB
testcase_77 AC 97 ms
77,056 KB
testcase_78 AC 104 ms
78,080 KB
testcase_79 AC 100 ms
78,720 KB
testcase_80 AC 100 ms
77,952 KB
testcase_81 AC 101 ms
78,720 KB
testcase_82 AC 109 ms
78,336 KB
testcase_83 AC 261 ms
93,344 KB
testcase_84 AC 249 ms
93,096 KB
testcase_85 AC 187 ms
86,792 KB
testcase_86 AC 230 ms
90,688 KB
testcase_87 AC 236 ms
92,236 KB
testcase_88 AC 111 ms
79,360 KB
testcase_89 AC 262 ms
93,408 KB
testcase_90 AC 185 ms
87,668 KB
testcase_91 AC 163 ms
85,376 KB
testcase_92 AC 124 ms
80,640 KB
testcase_93 AC 219 ms
89,980 KB
testcase_94 AC 198 ms
89,176 KB
testcase_95 AC 199 ms
88,908 KB
testcase_96 AC 241 ms
92,404 KB
testcase_97 AC 152 ms
83,968 KB
testcase_98 AC 233 ms
92,340 KB
testcase_99 AC 167 ms
86,232 KB
testcase_100 AC 248 ms
94,220 KB
testcase_101 AC 122 ms
80,128 KB
testcase_102 AC 110 ms
78,720 KB
testcase_103 AC 119 ms
80,384 KB
testcase_104 AC 134 ms
81,408 KB
testcase_105 AC 205 ms
90,096 KB
testcase_106 AC 155 ms
84,864 KB
testcase_107 AC 240 ms
93,264 KB
testcase_108 AC 246 ms
92,928 KB
testcase_109 AC 208 ms
89,776 KB
testcase_110 AC 198 ms
88,476 KB
testcase_111 AC 198 ms
89,348 KB
testcase_112 AC 131 ms
81,280 KB
testcase_113 AC 180 ms
87,392 KB
testcase_114 AC 152 ms
84,608 KB
testcase_115 AC 105 ms
79,616 KB
testcase_116 AC 168 ms
86,272 KB
testcase_117 AC 131 ms
81,280 KB
testcase_118 AC 227 ms
92,344 KB
testcase_119 AC 169 ms
86,152 KB
testcase_120 AC 232 ms
91,608 KB
testcase_121 AC 123 ms
80,512 KB
testcase_122 AC 161 ms
85,760 KB
testcase_123 AC 46 ms
53,760 KB
testcase_124 AC 299 ms
104,872 KB
testcase_125 AC 315 ms
104,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import deque
class LowLink:
  def __init__(self, N, M):
    self.V = N
    self.E = M
    self.edge = [[] for _ in range(self.V)]
    self.edges = [0]*M
    self.visited = [False]*N
    self.parent = [N]*N
    self.order = [N]*N
    self.low = [N]*N
  
  def add_edges(self, ind=1):
    for i in range(self.E):
      a,b = map(int, input().split())
      a -= ind
      b -= ind
      self.edge[a].append(b)
      self.edge[b].append(a)
      self.edges[i] = (a,b)

  def add_edge(self, a, b):
    self.edge[a].append(b)
    self.edge[b].append(a)

  def low_link(self, start):
    self.start = start
    stack = deque([start])
    self.parent[start] = -1
    self.order[start] = 0
    cnt = 1
    while stack:
      v = stack[-1]
      for u in self.edge[v]:
        if u==self.parent[v]:
          pass
        elif self.order[u]<self.order[v]: #後退辺の処理
          self.low[v] = min(self.low[v], self.order[u])
        elif self.parent[u]==N: #行きがけ
          self.order[u] = self.low[u] = cnt
          self.parent[u] = v
          stack.append(u)
          cnt += 1
          break
        else: #帰りがけ
          self.low[v] = min(self.low[v], self.low[u])
      else:
        stack.pop() #帰り
    return
  
  def bridge(self):
    res = []
    for i,(a,b) in enumerate(self.edges):
      if G.order[a]>G.order[b]:
        a,b = b,a
      if G.low[b]<=G.order[a]:
        res.append(i+1)
    return res
  
  def articulation(self):
    res = []
    for v in range(self.V):
      cnt = 0
      for u in self.edge[v]:
        if self.parent[v]==u or self.parent[u]!=v:
          continue
        if self.order[v]<=self.low[u]:
          cnt += 1
      if v==self.start:
        if cnt>=2:
          res.append(v)
      elif cnt>=1:
          res.append(v)
    return res


N = int(input())
G = LowLink(N, N)
G.add_edges(1)
G.low_link(0)
ans = G.bridge()
print(len(ans))
print(*ans)
0