結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 07:35:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,965 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 107,804 KB
最終ジャッジ日時 2023-09-27 21:07:48
合計ジャッジ時間 27,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,476 KB
testcase_01 AC 92 ms
71,464 KB
testcase_02 AC 92 ms
71,408 KB
testcase_03 AC 93 ms
71,292 KB
testcase_04 AC 92 ms
71,244 KB
testcase_05 AC 91 ms
71,400 KB
testcase_06 AC 90 ms
71,404 KB
testcase_07 AC 90 ms
71,468 KB
testcase_08 AC 90 ms
71,092 KB
testcase_09 AC 93 ms
71,484 KB
testcase_10 AC 90 ms
71,404 KB
testcase_11 AC 94 ms
71,432 KB
testcase_12 AC 92 ms
71,248 KB
testcase_13 AC 94 ms
71,596 KB
testcase_14 AC 92 ms
71,400 KB
testcase_15 AC 94 ms
71,396 KB
testcase_16 AC 90 ms
71,572 KB
testcase_17 AC 92 ms
71,592 KB
testcase_18 AC 91 ms
71,364 KB
testcase_19 AC 94 ms
71,552 KB
testcase_20 AC 91 ms
71,308 KB
testcase_21 AC 92 ms
71,596 KB
testcase_22 AC 93 ms
71,500 KB
testcase_23 AC 95 ms
71,252 KB
testcase_24 AC 95 ms
71,400 KB
testcase_25 AC 93 ms
71,312 KB
testcase_26 AC 94 ms
71,560 KB
testcase_27 AC 93 ms
71,412 KB
testcase_28 AC 94 ms
71,400 KB
testcase_29 AC 93 ms
71,588 KB
testcase_30 AC 95 ms
71,304 KB
testcase_31 AC 93 ms
71,456 KB
testcase_32 AC 95 ms
71,456 KB
testcase_33 AC 94 ms
71,632 KB
testcase_34 AC 96 ms
71,544 KB
testcase_35 AC 93 ms
71,484 KB
testcase_36 AC 94 ms
71,512 KB
testcase_37 AC 92 ms
71,556 KB
testcase_38 AC 93 ms
71,476 KB
testcase_39 AC 93 ms
71,304 KB
testcase_40 AC 93 ms
71,404 KB
testcase_41 AC 91 ms
71,456 KB
testcase_42 AC 93 ms
71,420 KB
testcase_43 AC 106 ms
77,204 KB
testcase_44 AC 99 ms
76,692 KB
testcase_45 AC 102 ms
76,804 KB
testcase_46 AC 108 ms
76,704 KB
testcase_47 AC 102 ms
76,436 KB
testcase_48 AC 106 ms
76,668 KB
testcase_49 AC 94 ms
71,548 KB
testcase_50 AC 109 ms
77,084 KB
testcase_51 AC 110 ms
76,860 KB
testcase_52 AC 108 ms
76,868 KB
testcase_53 AC 108 ms
76,992 KB
testcase_54 AC 110 ms
76,948 KB
testcase_55 AC 108 ms
76,564 KB
testcase_56 AC 92 ms
71,500 KB
testcase_57 AC 106 ms
76,892 KB
testcase_58 AC 104 ms
76,776 KB
testcase_59 AC 93 ms
71,620 KB
testcase_60 AC 98 ms
76,300 KB
testcase_61 AC 107 ms
76,740 KB
testcase_62 AC 93 ms
71,112 KB
testcase_63 AC 133 ms
77,812 KB
testcase_64 AC 125 ms
77,824 KB
testcase_65 AC 133 ms
78,596 KB
testcase_66 AC 131 ms
78,376 KB
testcase_67 AC 122 ms
77,736 KB
testcase_68 AC 130 ms
78,392 KB
testcase_69 AC 132 ms
77,796 KB
testcase_70 AC 124 ms
77,912 KB
testcase_71 AC 125 ms
78,384 KB
testcase_72 AC 133 ms
78,812 KB
testcase_73 AC 126 ms
77,844 KB
testcase_74 AC 131 ms
77,900 KB
testcase_75 AC 128 ms
77,440 KB
testcase_76 AC 117 ms
77,852 KB
testcase_77 AC 129 ms
77,848 KB
testcase_78 AC 135 ms
78,384 KB
testcase_79 AC 131 ms
77,488 KB
testcase_80 AC 135 ms
77,836 KB
testcase_81 AC 130 ms
77,480 KB
testcase_82 AC 144 ms
79,756 KB
testcase_83 AC 278 ms
95,004 KB
testcase_84 AC 262 ms
94,264 KB
testcase_85 AC 205 ms
88,136 KB
testcase_86 AC 252 ms
92,152 KB
testcase_87 AC 263 ms
93,564 KB
testcase_88 AC 141 ms
80,492 KB
testcase_89 AC 277 ms
94,656 KB
testcase_90 AC 213 ms
88,696 KB
testcase_91 AC 191 ms
86,644 KB
testcase_92 AC 157 ms
82,640 KB
testcase_93 AC 244 ms
91,020 KB
testcase_94 AC 233 ms
90,180 KB
testcase_95 AC 226 ms
90,048 KB
testcase_96 AC 270 ms
93,864 KB
testcase_97 AC 181 ms
84,716 KB
testcase_98 AC 270 ms
93,868 KB
testcase_99 AC 207 ms
87,848 KB
testcase_100 AC 280 ms
95,024 KB
testcase_101 AC 164 ms
82,036 KB
testcase_102 AC 142 ms
80,220 KB
testcase_103 AC 152 ms
82,656 KB
testcase_104 AC 167 ms
83,536 KB
testcase_105 AC 243 ms
90,984 KB
testcase_106 AC 191 ms
86,156 KB
testcase_107 AC 275 ms
94,476 KB
testcase_108 AC 276 ms
94,716 KB
testcase_109 AC 245 ms
90,768 KB
testcase_110 AC 232 ms
90,208 KB
testcase_111 AC 241 ms
91,088 KB
testcase_112 AC 171 ms
83,752 KB
testcase_113 AC 225 ms
89,632 KB
testcase_114 AC 193 ms
86,100 KB
testcase_115 AC 142 ms
80,816 KB
testcase_116 AC 198 ms
87,088 KB
testcase_117 AC 174 ms
83,404 KB
testcase_118 AC 271 ms
93,628 KB
testcase_119 AC 215 ms
87,720 KB
testcase_120 AC 269 ms
93,408 KB
testcase_121 AC 162 ms
83,144 KB
testcase_122 AC 200 ms
87,168 KB
testcase_123 AC 94 ms
71,112 KB
testcase_124 AC 362 ms
107,592 KB
testcase_125 AC 353 ms
107,804 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