結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 02:50:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 1,713 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 154,900 KB
最終ジャッジ日時 2023-09-27 21:00:57
合計ジャッジ時間 28,371 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
72,660 KB
testcase_01 AC 103 ms
72,620 KB
testcase_02 AC 100 ms
72,664 KB
testcase_03 AC 100 ms
72,660 KB
testcase_04 AC 104 ms
72,688 KB
testcase_05 AC 101 ms
72,744 KB
testcase_06 AC 103 ms
72,376 KB
testcase_07 AC 102 ms
72,660 KB
testcase_08 AC 106 ms
72,692 KB
testcase_09 AC 102 ms
72,588 KB
testcase_10 AC 102 ms
72,736 KB
testcase_11 AC 103 ms
72,616 KB
testcase_12 AC 101 ms
72,736 KB
testcase_13 AC 103 ms
72,380 KB
testcase_14 AC 101 ms
72,636 KB
testcase_15 AC 99 ms
72,688 KB
testcase_16 AC 100 ms
72,636 KB
testcase_17 AC 103 ms
72,764 KB
testcase_18 AC 101 ms
72,672 KB
testcase_19 AC 98 ms
72,524 KB
testcase_20 AC 101 ms
72,716 KB
testcase_21 AC 102 ms
72,644 KB
testcase_22 AC 103 ms
72,732 KB
testcase_23 AC 101 ms
72,664 KB
testcase_24 AC 98 ms
72,740 KB
testcase_25 AC 101 ms
72,484 KB
testcase_26 AC 100 ms
72,352 KB
testcase_27 AC 111 ms
72,376 KB
testcase_28 AC 109 ms
72,732 KB
testcase_29 AC 101 ms
72,768 KB
testcase_30 AC 102 ms
72,624 KB
testcase_31 AC 101 ms
72,640 KB
testcase_32 AC 107 ms
72,556 KB
testcase_33 AC 103 ms
72,288 KB
testcase_34 AC 103 ms
72,620 KB
testcase_35 AC 101 ms
72,764 KB
testcase_36 AC 103 ms
72,524 KB
testcase_37 AC 100 ms
72,240 KB
testcase_38 AC 99 ms
72,736 KB
testcase_39 AC 100 ms
72,588 KB
testcase_40 AC 103 ms
72,660 KB
testcase_41 AC 100 ms
72,672 KB
testcase_42 AC 99 ms
72,476 KB
testcase_43 AC 108 ms
77,200 KB
testcase_44 AC 102 ms
72,664 KB
testcase_45 AC 102 ms
72,696 KB
testcase_46 AC 105 ms
72,696 KB
testcase_47 AC 102 ms
72,236 KB
testcase_48 AC 103 ms
72,600 KB
testcase_49 AC 103 ms
72,668 KB
testcase_50 AC 108 ms
76,872 KB
testcase_51 AC 109 ms
77,168 KB
testcase_52 AC 110 ms
76,868 KB
testcase_53 AC 108 ms
76,576 KB
testcase_54 AC 110 ms
77,012 KB
testcase_55 AC 105 ms
72,696 KB
testcase_56 AC 101 ms
72,236 KB
testcase_57 AC 102 ms
72,352 KB
testcase_58 AC 103 ms
72,660 KB
testcase_59 AC 103 ms
72,720 KB
testcase_60 AC 102 ms
72,752 KB
testcase_61 AC 113 ms
77,208 KB
testcase_62 AC 103 ms
72,688 KB
testcase_63 AC 164 ms
84,508 KB
testcase_64 AC 132 ms
79,844 KB
testcase_65 AC 153 ms
82,188 KB
testcase_66 AC 148 ms
81,268 KB
testcase_67 AC 130 ms
79,484 KB
testcase_68 AC 150 ms
81,572 KB
testcase_69 AC 153 ms
82,628 KB
testcase_70 AC 134 ms
80,136 KB
testcase_71 AC 129 ms
79,004 KB
testcase_72 AC 158 ms
82,756 KB
testcase_73 AC 126 ms
79,308 KB
testcase_74 AC 148 ms
81,916 KB
testcase_75 AC 155 ms
80,984 KB
testcase_76 AC 116 ms
77,896 KB
testcase_77 AC 140 ms
81,092 KB
testcase_78 AC 153 ms
83,360 KB
testcase_79 AC 165 ms
83,552 KB
testcase_80 AC 157 ms
83,392 KB
testcase_81 AC 165 ms
83,704 KB
testcase_82 AC 155 ms
83,096 KB
testcase_83 AC 343 ms
122,668 KB
testcase_84 AC 320 ms
116,852 KB
testcase_85 AC 237 ms
107,752 KB
testcase_86 AC 285 ms
113,092 KB
testcase_87 AC 291 ms
112,604 KB
testcase_88 AC 165 ms
86,556 KB
testcase_89 AC 323 ms
122,732 KB
testcase_90 AC 252 ms
110,280 KB
testcase_91 AC 223 ms
99,472 KB
testcase_92 AC 180 ms
90,820 KB
testcase_93 AC 262 ms
111,352 KB
testcase_94 AC 252 ms
111,680 KB
testcase_95 AC 248 ms
111,036 KB
testcase_96 AC 286 ms
113,068 KB
testcase_97 AC 206 ms
95,888 KB
testcase_98 AC 323 ms
116,640 KB
testcase_99 AC 245 ms
106,268 KB
testcase_100 AC 325 ms
122,864 KB
testcase_101 AC 181 ms
91,780 KB
testcase_102 AC 165 ms
85,120 KB
testcase_103 AC 187 ms
90,924 KB
testcase_104 AC 200 ms
92,512 KB
testcase_105 AC 284 ms
111,488 KB
testcase_106 AC 207 ms
97,356 KB
testcase_107 AC 326 ms
122,648 KB
testcase_108 AC 317 ms
117,068 KB
testcase_109 AC 266 ms
111,284 KB
testcase_110 AC 271 ms
111,516 KB
testcase_111 AC 266 ms
110,996 KB
testcase_112 AC 190 ms
92,476 KB
testcase_113 AC 262 ms
110,592 KB
testcase_114 AC 208 ms
97,340 KB
testcase_115 AC 171 ms
88,132 KB
testcase_116 AC 215 ms
99,252 KB
testcase_117 AC 190 ms
93,256 KB
testcase_118 AC 298 ms
113,184 KB
testcase_119 AC 225 ms
102,340 KB
testcase_120 AC 297 ms
112,784 KB
testcase_121 AC 183 ms
93,260 KB
testcase_122 AC 232 ms
99,828 KB
testcase_123 AC 99 ms
72,376 KB
testcase_124 AC 460 ms
154,900 KB
testcase_125 AC 461 ms
154,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,os,io
input = sys.stdin.readline
from collections import defaultdict
class Graph:
  def __init__(self, N):
    self.V = N
    self.edge = [[] for _ in range(self.V)]
    self.edges = defaultdict(lambda: 0)
    self.prev = [N]*N
    self.parent = [N]*N
  
  def add_edge(self, a, b, i):
    self.edge[a].append(b)
    self.edges[(a,b)] = i

  def dfs(self, start):
    stack = [start]
    self.parent[start] = -1
    self.visited[start] = 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)
          break
        else:
          return u
      else:
        stack.pop()

  def bfs(self, start):
    stack = deque([start])
    self.parent[start] = -1
    while stack:
      v = stack.pop()
      for u in self.edge[v]:
        if u==self.parent[v]:
          continue
        if self.parent[u]!=N:
          return v,u
        self.parent[u]=v
        #頂点に対する処理
        stack.append(u)
    return

from collections import deque
from copy import copy

N = int(input())
G = Graph(N)
for i in range(N):
  a,b = map(int, input().split())
  a,b = min(a-1,b-1), max(a-1,b-1)
  G.add_edge(a,b,i+1)
  G.add_edge(b,a,i+1)

v,u = G.bfs(0)
lis = []
lis.append(G.edges[v,u])
while G.parent[v]!=-1:
  lis.append(G.edges[(G.parent[v],v)])
  v = G.parent[v]
while G.parent[u]!=-1:
  lis.append(G.edges[(G.parent[u],u)])
  u = G.parent[u]
lis.sort()
ans = set()
from collections import Counter
c = Counter(lis)
for k,val in c.items():
  if val==1:
    ans.add(k)
print(len(ans))
print(*ans)


0