結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 01:43:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,992 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 298,348 KB
最終ジャッジ日時 2023-09-27 20:49:15
合計ジャッジ時間 38,371 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
80,404 KB
testcase_01 AC 103 ms
76,068 KB
testcase_02 AC 104 ms
76,204 KB
testcase_03 AC 104 ms
76,176 KB
testcase_04 AC 102 ms
76,148 KB
testcase_05 AC 103 ms
75,988 KB
testcase_06 AC 104 ms
76,272 KB
testcase_07 AC 102 ms
76,188 KB
testcase_08 AC 107 ms
76,036 KB
testcase_09 AC 106 ms
76,164 KB
testcase_10 AC 102 ms
76,024 KB
testcase_11 AC 104 ms
76,160 KB
testcase_12 AC 104 ms
76,160 KB
testcase_13 AC 104 ms
76,164 KB
testcase_14 AC 99 ms
76,156 KB
testcase_15 AC 102 ms
75,976 KB
testcase_16 AC 100 ms
76,160 KB
testcase_17 AC 103 ms
75,920 KB
testcase_18 AC 101 ms
76,164 KB
testcase_19 AC 101 ms
76,172 KB
testcase_20 AC 100 ms
76,180 KB
testcase_21 AC 101 ms
75,988 KB
testcase_22 AC 103 ms
76,076 KB
testcase_23 AC 101 ms
75,984 KB
testcase_24 AC 102 ms
76,224 KB
testcase_25 AC 107 ms
75,976 KB
testcase_26 AC 101 ms
75,920 KB
testcase_27 AC 102 ms
75,968 KB
testcase_28 AC 104 ms
76,188 KB
testcase_29 AC 102 ms
75,824 KB
testcase_30 AC 101 ms
76,072 KB
testcase_31 AC 107 ms
75,924 KB
testcase_32 AC 98 ms
76,076 KB
testcase_33 AC 98 ms
76,048 KB
testcase_34 AC 104 ms
76,040 KB
testcase_35 AC 101 ms
76,084 KB
testcase_36 AC 102 ms
75,964 KB
testcase_37 AC 102 ms
76,040 KB
testcase_38 AC 102 ms
76,212 KB
testcase_39 AC 102 ms
76,100 KB
testcase_40 AC 100 ms
76,072 KB
testcase_41 AC 102 ms
76,156 KB
testcase_42 AC 102 ms
75,732 KB
testcase_43 AC 119 ms
77,772 KB
testcase_44 AC 105 ms
77,108 KB
testcase_45 AC 106 ms
76,856 KB
testcase_46 AC 113 ms
77,748 KB
testcase_47 AC 113 ms
77,460 KB
testcase_48 AC 115 ms
77,752 KB
testcase_49 AC 102 ms
75,716 KB
testcase_50 AC 120 ms
77,612 KB
testcase_51 AC 121 ms
77,972 KB
testcase_52 AC 120 ms
77,788 KB
testcase_53 AC 121 ms
77,660 KB
testcase_54 AC 122 ms
77,652 KB
testcase_55 AC 121 ms
77,600 KB
testcase_56 AC 105 ms
75,724 KB
testcase_57 AC 113 ms
77,512 KB
testcase_58 AC 115 ms
77,628 KB
testcase_59 AC 100 ms
76,152 KB
testcase_60 AC 105 ms
77,588 KB
testcase_61 AC 116 ms
77,736 KB
testcase_62 AC 104 ms
76,204 KB
testcase_63 AC 186 ms
86,264 KB
testcase_64 AC 147 ms
79,996 KB
testcase_65 AC 174 ms
83,364 KB
testcase_66 AC 163 ms
82,616 KB
testcase_67 AC 137 ms
79,652 KB
testcase_68 AC 172 ms
83,120 KB
testcase_69 AC 175 ms
83,676 KB
testcase_70 AC 150 ms
80,352 KB
testcase_71 AC 141 ms
79,520 KB
testcase_72 AC 178 ms
84,212 KB
testcase_73 AC 138 ms
79,704 KB
testcase_74 AC 173 ms
83,784 KB
testcase_75 AC 168 ms
82,392 KB
testcase_76 AC 126 ms
79,144 KB
testcase_77 AC 161 ms
82,104 KB
testcase_78 AC 182 ms
85,072 KB
testcase_79 AC 185 ms
84,960 KB
testcase_80 AC 179 ms
84,632 KB
testcase_81 AC 188 ms
85,244 KB
testcase_82 AC 180 ms
84,468 KB
testcase_83 AC 675 ms
202,456 KB
testcase_84 AC 645 ms
193,864 KB
testcase_85 AC 340 ms
114,804 KB
testcase_86 AC 478 ms
146,008 KB
testcase_87 AC 565 ms
183,976 KB
testcase_88 AC 193 ms
88,680 KB
testcase_89 AC 577 ms
184,944 KB
testcase_90 AC 379 ms
122,616 KB
testcase_91 AC 325 ms
113,316 KB
testcase_92 AC 238 ms
96,544 KB
testcase_93 AC 376 ms
123,640 KB
testcase_94 AC 418 ms
148,260 KB
testcase_95 AC 412 ms
143,616 KB
testcase_96 AC 550 ms
177,116 KB
testcase_97 AC 286 ms
105,800 KB
testcase_98 AC 552 ms
179,564 KB
testcase_99 AC 357 ms
128,168 KB
testcase_100 AC 591 ms
202,276 KB
testcase_101 AC 224 ms
92,244 KB
testcase_102 AC 184 ms
86,760 KB
testcase_103 AC 230 ms
93,136 KB
testcase_104 AC 229 ms
96,492 KB
testcase_105 AC 460 ms
141,956 KB
testcase_106 AC 298 ms
105,828 KB
testcase_107 AC 621 ms
197,432 KB
testcase_108 AC 570 ms
177,416 KB
testcase_109 AC 386 ms
128,664 KB
testcase_110 AC 407 ms
139,012 KB
testcase_111 AC 413 ms
141,440 KB
testcase_112 AC 260 ms
98,060 KB
testcase_113 AC 428 ms
154,684 KB
testcase_114 AC 267 ms
100,792 KB
testcase_115 AC 193 ms
88,116 KB
testcase_116 AC 350 ms
120,452 KB
testcase_117 AC 252 ms
100,940 KB
testcase_118 AC 497 ms
157,036 KB
testcase_119 AC 359 ms
119,680 KB
testcase_120 AC 555 ms
166,808 KB
testcase_121 AC 229 ms
93,864 KB
testcase_122 AC 345 ms
113,480 KB
testcase_123 AC 102 ms
76,036 KB
testcase_124 TLE -
testcase_125 -- -
権限があれば一括ダウンロードができます

ソースコード

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.visited = [0]*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 bfs1(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 u
        self.parent[u]=v
        #頂点に対する処理
        stack.append(u)
    return
  
  
  def bfs(self, start):
    d = deque()
    d.append([[start],{start:True}])
    cyc = []
    cnt = 0
    while len(d)>0 and cnt<N*2+1:
      vs, tf = d.popleft()
      for w in self.edge[vs[-1]]:
        if len(vs)>1 and w==vs[-2]:
          continue
        lis,dic = copy(vs), copy(tf)
        lis.append(w)
        dic[w] = True
        if w==start and len(lis)>len(cyc):
          cyc = lis
        elif w not in tf:
          d.append([lis,dic])
      cnt += 1
    return cyc

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)

ans = set()
cyc = G.bfs1(0)
vs = G.bfs(cyc)
for v0,v1 in zip(vs[:-1],vs[1:]):
  ans.add(G.edges[(v0,v1)])
ans = list(ans)
print(len(ans))
print(*ans)


0