結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 01:03:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,076 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 121,164 KB
最終ジャッジ日時 2023-09-27 20:37:04
合計ジャッジ時間 31,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
76,288 KB
testcase_01 WA -
testcase_02 AC 97 ms
76,224 KB
testcase_03 AC 96 ms
76,156 KB
testcase_04 AC 103 ms
76,288 KB
testcase_05 AC 96 ms
76,100 KB
testcase_06 AC 99 ms
76,080 KB
testcase_07 AC 93 ms
76,168 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 96 ms
76,104 KB
testcase_11 WA -
testcase_12 AC 95 ms
76,024 KB
testcase_13 WA -
testcase_14 AC 96 ms
76,304 KB
testcase_15 AC 99 ms
76,268 KB
testcase_16 AC 96 ms
76,284 KB
testcase_17 AC 96 ms
76,088 KB
testcase_18 AC 95 ms
76,184 KB
testcase_19 AC 95 ms
76,088 KB
testcase_20 AC 96 ms
76,328 KB
testcase_21 AC 95 ms
76,308 KB
testcase_22 AC 95 ms
76,292 KB
testcase_23 AC 95 ms
76,104 KB
testcase_24 AC 97 ms
76,168 KB
testcase_25 AC 98 ms
76,244 KB
testcase_26 WA -
testcase_27 AC 95 ms
76,256 KB
testcase_28 AC 96 ms
76,256 KB
testcase_29 WA -
testcase_30 AC 96 ms
76,200 KB
testcase_31 AC 100 ms
76,232 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 97 ms
76,336 KB
testcase_36 WA -
testcase_37 AC 97 ms
76,108 KB
testcase_38 AC 97 ms
75,956 KB
testcase_39 WA -
testcase_40 AC 96 ms
75,976 KB
testcase_41 AC 95 ms
76,220 KB
testcase_42 AC 97 ms
76,328 KB
testcase_43 WA -
testcase_44 AC 102 ms
76,896 KB
testcase_45 AC 100 ms
77,016 KB
testcase_46 WA -
testcase_47 AC 103 ms
77,000 KB
testcase_48 AC 106 ms
77,744 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 109 ms
78,044 KB
testcase_53 WA -
testcase_54 AC 108 ms
77,972 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 AC 107 ms
77,756 KB
testcase_59 AC 95 ms
76,336 KB
testcase_60 WA -
testcase_61 AC 110 ms
77,940 KB
testcase_62 AC 99 ms
76,224 KB
testcase_63 WA -
testcase_64 AC 131 ms
79,844 KB
testcase_65 AC 136 ms
80,396 KB
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 139 ms
80,160 KB
testcase_69 AC 141 ms
80,564 KB
testcase_70 AC 134 ms
80,160 KB
testcase_71 AC 128 ms
79,724 KB
testcase_72 WA -
testcase_73 WA -
testcase_74 AC 135 ms
80,616 KB
testcase_75 AC 142 ms
80,236 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 149 ms
82,016 KB
testcase_80 WA -
testcase_81 AC 149 ms
81,772 KB
testcase_82 AC 150 ms
80,516 KB
testcase_83 AC 410 ms
119,560 KB
testcase_84 WA -
testcase_85 WA -
testcase_86 AC 318 ms
109,420 KB
testcase_87 WA -
testcase_88 AC 159 ms
83,316 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 AC 286 ms
105,852 KB
testcase_95 WA -
testcase_96 AC 352 ms
117,728 KB
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 AC 172 ms
85,964 KB
testcase_102 AC 154 ms
82,880 KB
testcase_103 AC 176 ms
87,236 KB
testcase_104 AC 197 ms
90,204 KB
testcase_105 AC 322 ms
109,512 KB
testcase_106 AC 225 ms
93,896 KB
testcase_107 AC 355 ms
118,908 KB
testcase_108 AC 370 ms
118,424 KB
testcase_109 WA -
testcase_110 AC 294 ms
105,632 KB
testcase_111 AC 293 ms
106,464 KB
testcase_112 AC 195 ms
89,208 KB
testcase_113 WA -
testcase_114 AC 217 ms
93,440 KB
testcase_115 AC 161 ms
83,792 KB
testcase_116 WA -
testcase_117 AC 199 ms
89,544 KB
testcase_118 AC 324 ms
114,644 KB
testcase_119 AC 259 ms
99,680 KB
testcase_120 AC 352 ms
116,256 KB
testcase_121 AC 188 ms
87,680 KB
testcase_122 AC 239 ms
95,476 KB
testcase_123 AC 95 ms
76,172 KB
testcase_124 TLE -
testcase_125 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

  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 = [start]
    self.parent[start] = -1
    while stack:
      v = stack.pop()
      for u,i 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(dict())
    cyc = dict()
    cnt = 0
    while len(d)>0 and cnt<N+1:
      es = d.popleft()
      if len(es):
        v0,v = self.edges[list(es.keys())[-1]]
      else:
        v0,v = start,start
      for w,i in self.edge[v]:
        if w==v0:
          continue
        if i not in es:
          dic = copy(es)
          dic[i] = True
          if w==start:
            for i in range(N+1,2*N+1):
              if i in dic:
                dic[i-N] = True
                del dic[i]
            if len(dic)>len(cyc):
              cyc = dic
          else:
            d.append(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())
  G.add_edge(a-1,b-1,i+1)
  G.add_edge(b-1,a-1,N+i+1)

ans = set()
cyc = G.bfs1(0)
es = G.bfs(cyc)
for e in es.keys():
  ans.add(e)
ans = list(ans)
print(len(ans))
print(*ans)


0