結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 05:35:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 545 ms / 2,000 ms
コード長 2,439 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 113,540 KB
最終ジャッジ日時 2023-09-27 21:04:00
合計ジャッジ時間 31,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,248 KB
testcase_01 AC 95 ms
71,388 KB
testcase_02 AC 97 ms
71,404 KB
testcase_03 AC 97 ms
71,564 KB
testcase_04 AC 97 ms
71,248 KB
testcase_05 AC 96 ms
71,476 KB
testcase_06 AC 95 ms
71,248 KB
testcase_07 AC 97 ms
71,472 KB
testcase_08 AC 96 ms
71,476 KB
testcase_09 AC 94 ms
71,484 KB
testcase_10 AC 95 ms
71,400 KB
testcase_11 AC 97 ms
71,592 KB
testcase_12 AC 96 ms
71,420 KB
testcase_13 AC 97 ms
71,368 KB
testcase_14 AC 96 ms
71,564 KB
testcase_15 AC 95 ms
71,104 KB
testcase_16 AC 96 ms
71,544 KB
testcase_17 AC 95 ms
71,244 KB
testcase_18 AC 97 ms
71,300 KB
testcase_19 AC 95 ms
71,396 KB
testcase_20 AC 95 ms
71,516 KB
testcase_21 AC 97 ms
71,244 KB
testcase_22 AC 96 ms
71,464 KB
testcase_23 AC 95 ms
71,112 KB
testcase_24 AC 94 ms
71,248 KB
testcase_25 AC 97 ms
71,464 KB
testcase_26 AC 95 ms
71,576 KB
testcase_27 AC 97 ms
71,588 KB
testcase_28 AC 98 ms
71,540 KB
testcase_29 AC 94 ms
71,492 KB
testcase_30 AC 94 ms
71,484 KB
testcase_31 AC 97 ms
71,368 KB
testcase_32 AC 93 ms
71,504 KB
testcase_33 AC 97 ms
71,368 KB
testcase_34 AC 96 ms
71,484 KB
testcase_35 AC 97 ms
71,468 KB
testcase_36 AC 96 ms
71,476 KB
testcase_37 AC 98 ms
71,588 KB
testcase_38 AC 97 ms
71,396 KB
testcase_39 AC 98 ms
71,564 KB
testcase_40 AC 97 ms
71,576 KB
testcase_41 AC 96 ms
71,336 KB
testcase_42 AC 97 ms
71,240 KB
testcase_43 AC 122 ms
77,120 KB
testcase_44 AC 105 ms
76,548 KB
testcase_45 AC 109 ms
77,220 KB
testcase_46 AC 119 ms
76,968 KB
testcase_47 AC 108 ms
76,324 KB
testcase_48 AC 117 ms
77,192 KB
testcase_49 AC 97 ms
71,464 KB
testcase_50 AC 123 ms
77,116 KB
testcase_51 AC 127 ms
77,224 KB
testcase_52 AC 126 ms
77,228 KB
testcase_53 AC 120 ms
77,180 KB
testcase_54 AC 127 ms
77,228 KB
testcase_55 AC 121 ms
76,816 KB
testcase_56 AC 102 ms
72,124 KB
testcase_57 AC 114 ms
76,952 KB
testcase_58 AC 117 ms
77,096 KB
testcase_59 AC 99 ms
71,216 KB
testcase_60 AC 107 ms
76,308 KB
testcase_61 AC 121 ms
76,984 KB
testcase_62 AC 100 ms
72,136 KB
testcase_63 AC 159 ms
80,656 KB
testcase_64 AC 142 ms
78,524 KB
testcase_65 AC 157 ms
79,936 KB
testcase_66 AC 155 ms
79,520 KB
testcase_67 AC 141 ms
78,612 KB
testcase_68 AC 154 ms
79,632 KB
testcase_69 AC 154 ms
80,012 KB
testcase_70 AC 141 ms
78,684 KB
testcase_71 AC 143 ms
78,512 KB
testcase_72 AC 154 ms
80,084 KB
testcase_73 AC 144 ms
78,500 KB
testcase_74 AC 157 ms
80,080 KB
testcase_75 AC 146 ms
79,496 KB
testcase_76 AC 133 ms
78,708 KB
testcase_77 AC 151 ms
79,592 KB
testcase_78 AC 166 ms
80,788 KB
testcase_79 AC 162 ms
80,376 KB
testcase_80 AC 159 ms
80,368 KB
testcase_81 AC 159 ms
80,384 KB
testcase_82 AC 178 ms
81,120 KB
testcase_83 AC 407 ms
102,160 KB
testcase_84 AC 378 ms
101,576 KB
testcase_85 AC 280 ms
92,476 KB
testcase_86 AC 385 ms
98,796 KB
testcase_87 AC 395 ms
100,052 KB
testcase_88 AC 170 ms
81,440 KB
testcase_89 AC 391 ms
101,600 KB
testcase_90 AC 300 ms
93,552 KB
testcase_91 AC 270 ms
90,232 KB
testcase_92 AC 198 ms
85,312 KB
testcase_93 AC 354 ms
96,932 KB
testcase_94 AC 327 ms
95,356 KB
testcase_95 AC 316 ms
95,180 KB
testcase_96 AC 388 ms
100,392 KB
testcase_97 AC 240 ms
88,432 KB
testcase_98 AC 390 ms
100,596 KB
testcase_99 AC 286 ms
92,056 KB
testcase_100 AC 406 ms
102,456 KB
testcase_101 AC 208 ms
84,428 KB
testcase_102 AC 170 ms
80,856 KB
testcase_103 AC 196 ms
85,200 KB
testcase_104 AC 220 ms
87,064 KB
testcase_105 AC 355 ms
97,096 KB
testcase_106 AC 258 ms
89,280 KB
testcase_107 AC 416 ms
101,860 KB
testcase_108 AC 404 ms
101,364 KB
testcase_109 AC 343 ms
96,772 KB
testcase_110 AC 323 ms
94,892 KB
testcase_111 AC 335 ms
96,232 KB
testcase_112 AC 218 ms
86,444 KB
testcase_113 AC 305 ms
94,776 KB
testcase_114 AC 271 ms
89,436 KB
testcase_115 AC 172 ms
81,696 KB
testcase_116 AC 257 ms
90,716 KB
testcase_117 AC 221 ms
86,564 KB
testcase_118 AC 376 ms
100,420 KB
testcase_119 AC 296 ms
91,972 KB
testcase_120 AC 375 ms
99,324 KB
testcase_121 AC 209 ms
85,304 KB
testcase_122 AC 272 ms
90,728 KB
testcase_123 AC 97 ms
71,596 KB
testcase_124 AC 545 ms
113,540 KB
testcase_125 AC 521 ms
113,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

  def dfs(self, start):
    stack = deque([start])
    self.parent[start] = -1
    #記録したい値の配列を定義
    self.order[start] = 0
    cnt = 1
    while stack:
      v = stack[-1]
      for u,i in self.edge[v]:
        if u==self.parent[v]:
          continue
        if self.parent[u]==N: #行き
          self.parent[u]=v
          stack.append(u)
          self.order[u] = cnt
          self.edge_tf[i] = True
          cnt += 1
          break
      else:
        stack.pop() #帰り
    return

  def dfs2(self, start):
    stack = deque([start])
    self.visited[start] = True
    #記録したい値の配列を定義
    self.low0 = self.order[:]
    self.low1 = self.order[:]
    while stack:
      v = stack[-1]
      for u,i in self.edge[v]:
        if self.edge_tf[i] and self.order[v]>self.order[u]:
          continue
        if self.visited[u]==False: #行き
          self.visited[u]=True
          stack.append(u)
          break
        else:
          if self.edge_tf[i]:
            self.low0[v] = min(self.low0[v], self.low0[u])
            self.low1[v] = min(self.low1[v], self.low1[u])
          else:
            self.low1[v] = min(self.low1[v], self.low0[u])
      else:
        stack.pop() #帰り
    return
  
  def bfs(self, start):
    d = deque()
    self.visited[start]=True
    d.append((start,cnt))
    while len(d)>0:
      v,cnt = d.popleft()
      for w in self.edge[v]:
        if self.visited[w]==False:
          self.visited[w]=True
          d.append((w,cnt+1))
    return cnt

N = int(input())
G = UnDirectedGraph(N)
G.add_edges(N)
G.dfs(0)
G.dfs2(0)
ans = []
for i,(a,b) in enumerate(G.edges):
  if G.edge_tf[i]==False:
    ans.append(i+1)
    continue
  if G.order[a]>G.order[b]:
    a,b = b,a
  if G.low1[b]<=G.order[a]:
    ans.append(i+1)
print(len(ans))
print(*ans)
0