結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 01:44:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,991 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 138,180 KB
最終ジャッジ日時 2023-09-27 20:50:12
合計ジャッジ時間 32,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
75,936 KB
testcase_01 AC 96 ms
75,928 KB
testcase_02 AC 98 ms
76,080 KB
testcase_03 AC 96 ms
76,176 KB
testcase_04 AC 96 ms
76,252 KB
testcase_05 AC 95 ms
76,084 KB
testcase_06 AC 96 ms
76,232 KB
testcase_07 AC 96 ms
76,108 KB
testcase_08 AC 97 ms
76,176 KB
testcase_09 AC 98 ms
76,020 KB
testcase_10 AC 97 ms
76,020 KB
testcase_11 AC 95 ms
76,040 KB
testcase_12 AC 96 ms
76,020 KB
testcase_13 AC 98 ms
76,260 KB
testcase_14 AC 99 ms
75,936 KB
testcase_15 AC 98 ms
76,024 KB
testcase_16 AC 99 ms
76,092 KB
testcase_17 AC 97 ms
75,816 KB
testcase_18 AC 100 ms
76,252 KB
testcase_19 AC 98 ms
76,160 KB
testcase_20 AC 100 ms
76,212 KB
testcase_21 AC 98 ms
76,248 KB
testcase_22 AC 97 ms
76,152 KB
testcase_23 AC 95 ms
76,124 KB
testcase_24 AC 101 ms
76,120 KB
testcase_25 AC 96 ms
76,188 KB
testcase_26 WA -
testcase_27 AC 96 ms
76,220 KB
testcase_28 AC 101 ms
75,928 KB
testcase_29 AC 103 ms
76,288 KB
testcase_30 AC 97 ms
76,072 KB
testcase_31 AC 101 ms
76,156 KB
testcase_32 AC 96 ms
76,152 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 99 ms
75,820 KB
testcase_36 WA -
testcase_37 AC 96 ms
76,140 KB
testcase_38 AC 99 ms
76,168 KB
testcase_39 AC 95 ms
76,044 KB
testcase_40 AC 98 ms
76,020 KB
testcase_41 AC 92 ms
76,156 KB
testcase_42 AC 97 ms
76,172 KB
testcase_43 WA -
testcase_44 AC 98 ms
76,040 KB
testcase_45 AC 99 ms
76,252 KB
testcase_46 WA -
testcase_47 AC 101 ms
76,036 KB
testcase_48 AC 109 ms
77,752 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 112 ms
78,072 KB
testcase_53 WA -
testcase_54 AC 110 ms
77,844 KB
testcase_55 AC 109 ms
77,640 KB
testcase_56 AC 99 ms
76,260 KB
testcase_57 WA -
testcase_58 AC 107 ms
77,668 KB
testcase_59 AC 99 ms
76,260 KB
testcase_60 WA -
testcase_61 AC 106 ms
77,480 KB
testcase_62 AC 96 ms
75,824 KB
testcase_63 WA -
testcase_64 AC 140 ms
80,188 KB
testcase_65 AC 166 ms
83,400 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 159 ms
83,140 KB
testcase_69 AC 167 ms
83,716 KB
testcase_70 AC 142 ms
80,528 KB
testcase_71 AC 143 ms
79,636 KB
testcase_72 WA -
testcase_73 WA -
testcase_74 AC 159 ms
83,768 KB
testcase_75 AC 157 ms
82,368 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 168 ms
85,132 KB
testcase_80 WA -
testcase_81 AC 172 ms
85,328 KB
testcase_82 AC 176 ms
84,456 KB
testcase_83 AC 440 ms
136,984 KB
testcase_84 WA -
testcase_85 WA -
testcase_86 AC 354 ms
121,284 KB
testcase_87 WA -
testcase_88 AC 176 ms
88,408 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 AC 334 ms
116,408 KB
testcase_95 WA -
testcase_96 AC 400 ms
136,560 KB
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 AC 197 ms
91,908 KB
testcase_102 AC 175 ms
86,836 KB
testcase_103 AC 207 ms
91,816 KB
testcase_104 AC 233 ms
96,504 KB
testcase_105 AC 367 ms
122,972 KB
testcase_106 AC 258 ms
101,276 KB
testcase_107 AC 420 ms
134,140 KB
testcase_108 AC 432 ms
136,620 KB
testcase_109 WA -
testcase_110 AC 332 ms
117,104 KB
testcase_111 AC 349 ms
119,036 KB
testcase_112 AC 221 ms
95,532 KB
testcase_113 WA -
testcase_114 AC 256 ms
100,832 KB
testcase_115 AC 182 ms
88,000 KB
testcase_116 WA -
testcase_117 AC 227 ms
96,972 KB
testcase_118 AC 407 ms
129,176 KB
testcase_119 AC 291 ms
106,496 KB
testcase_120 AC 406 ms
133,880 KB
testcase_121 AC 210 ms
92,784 KB
testcase_122 AC 271 ms
103,736 KB
testcase_123 AC 95 ms
76,156 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+10:
      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