結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 05:35:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 2,439 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 115,072 KB
最終ジャッジ日時 2024-07-20 15:34:54
合計ジャッジ時間 23,722 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
54,016 KB
testcase_01 AC 46 ms
53,888 KB
testcase_02 AC 46 ms
54,144 KB
testcase_03 AC 46 ms
54,144 KB
testcase_04 AC 46 ms
54,144 KB
testcase_05 AC 45 ms
54,144 KB
testcase_06 AC 44 ms
54,016 KB
testcase_07 AC 43 ms
54,272 KB
testcase_08 AC 44 ms
54,144 KB
testcase_09 AC 45 ms
54,144 KB
testcase_10 AC 43 ms
54,400 KB
testcase_11 AC 45 ms
54,400 KB
testcase_12 AC 44 ms
54,016 KB
testcase_13 AC 45 ms
54,144 KB
testcase_14 AC 44 ms
54,528 KB
testcase_15 AC 47 ms
54,144 KB
testcase_16 AC 45 ms
54,528 KB
testcase_17 AC 44 ms
54,144 KB
testcase_18 AC 43 ms
54,144 KB
testcase_19 AC 44 ms
54,016 KB
testcase_20 AC 45 ms
54,400 KB
testcase_21 AC 44 ms
54,272 KB
testcase_22 AC 44 ms
54,400 KB
testcase_23 AC 44 ms
54,144 KB
testcase_24 AC 44 ms
54,272 KB
testcase_25 AC 44 ms
54,144 KB
testcase_26 AC 45 ms
54,272 KB
testcase_27 AC 45 ms
54,528 KB
testcase_28 AC 45 ms
54,144 KB
testcase_29 AC 44 ms
54,528 KB
testcase_30 AC 44 ms
53,888 KB
testcase_31 AC 46 ms
54,656 KB
testcase_32 AC 44 ms
54,144 KB
testcase_33 AC 46 ms
54,272 KB
testcase_34 AC 44 ms
54,528 KB
testcase_35 AC 45 ms
54,400 KB
testcase_36 AC 45 ms
54,144 KB
testcase_37 AC 45 ms
54,400 KB
testcase_38 AC 45 ms
54,528 KB
testcase_39 AC 44 ms
54,400 KB
testcase_40 AC 43 ms
54,528 KB
testcase_41 AC 44 ms
54,400 KB
testcase_42 AC 43 ms
54,144 KB
testcase_43 AC 71 ms
68,992 KB
testcase_44 AC 55 ms
62,592 KB
testcase_45 AC 57 ms
63,616 KB
testcase_46 AC 74 ms
68,992 KB
testcase_47 AC 56 ms
63,104 KB
testcase_48 AC 70 ms
66,816 KB
testcase_49 AC 51 ms
54,912 KB
testcase_50 AC 84 ms
70,400 KB
testcase_51 AC 85 ms
71,552 KB
testcase_52 AC 90 ms
71,680 KB
testcase_53 AC 74 ms
68,736 KB
testcase_54 AC 78 ms
71,808 KB
testcase_55 AC 70 ms
68,992 KB
testcase_56 AC 47 ms
54,656 KB
testcase_57 AC 64 ms
66,304 KB
testcase_58 AC 66 ms
66,816 KB
testcase_59 AC 46 ms
54,400 KB
testcase_60 AC 52 ms
61,824 KB
testcase_61 AC 72 ms
68,608 KB
testcase_62 AC 47 ms
54,912 KB
testcase_63 AC 111 ms
78,976 KB
testcase_64 AC 99 ms
77,764 KB
testcase_65 AC 118 ms
78,464 KB
testcase_66 AC 117 ms
77,952 KB
testcase_67 AC 104 ms
77,440 KB
testcase_68 AC 114 ms
78,208 KB
testcase_69 AC 114 ms
78,464 KB
testcase_70 AC 99 ms
77,824 KB
testcase_71 AC 100 ms
77,480 KB
testcase_72 AC 105 ms
78,592 KB
testcase_73 AC 98 ms
77,312 KB
testcase_74 AC 116 ms
78,848 KB
testcase_75 AC 103 ms
77,824 KB
testcase_76 AC 92 ms
77,184 KB
testcase_77 AC 103 ms
77,824 KB
testcase_78 AC 119 ms
79,616 KB
testcase_79 AC 107 ms
78,720 KB
testcase_80 AC 109 ms
78,464 KB
testcase_81 AC 108 ms
79,232 KB
testcase_82 AC 120 ms
79,488 KB
testcase_83 AC 337 ms
100,104 KB
testcase_84 AC 333 ms
99,632 KB
testcase_85 AC 231 ms
91,464 KB
testcase_86 AC 306 ms
97,280 KB
testcase_87 AC 325 ms
98,764 KB
testcase_88 AC 119 ms
80,896 KB
testcase_89 AC 335 ms
100,484 KB
testcase_90 AC 238 ms
91,980 KB
testcase_91 AC 199 ms
89,344 KB
testcase_92 AC 144 ms
83,584 KB
testcase_93 AC 272 ms
95,772 KB
testcase_94 AC 256 ms
93,784 KB
testcase_95 AC 262 ms
94,024 KB
testcase_96 AC 330 ms
99,540 KB
testcase_97 AC 188 ms
87,168 KB
testcase_98 AC 321 ms
99,360 KB
testcase_99 AC 218 ms
90,516 KB
testcase_100 AC 342 ms
100,488 KB
testcase_101 AC 152 ms
83,072 KB
testcase_102 AC 131 ms
80,512 KB
testcase_103 AC 145 ms
82,944 KB
testcase_104 AC 163 ms
85,248 KB
testcase_105 AC 285 ms
95,508 KB
testcase_106 AC 205 ms
87,936 KB
testcase_107 AC 312 ms
99,888 KB
testcase_108 AC 302 ms
99,656 KB
testcase_109 AC 249 ms
95,572 KB
testcase_110 AC 228 ms
93,724 KB
testcase_111 AC 244 ms
94,876 KB
testcase_112 AC 150 ms
84,864 KB
testcase_113 AC 210 ms
93,020 KB
testcase_114 AC 186 ms
88,320 KB
testcase_115 AC 114 ms
80,000 KB
testcase_116 AC 181 ms
89,600 KB
testcase_117 AC 150 ms
85,248 KB
testcase_118 AC 283 ms
98,732 KB
testcase_119 AC 210 ms
90,300 KB
testcase_120 AC 295 ms
98,104 KB
testcase_121 AC 145 ms
83,712 KB
testcase_122 AC 201 ms
89,728 KB
testcase_123 AC 41 ms
54,528 KB
testcase_124 AC 386 ms
115,072 KB
testcase_125 AC 395 ms
114,696 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