結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 00:48:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 308,408 KB
最終ジャッジ日時 2023-09-27 20:31:42
合計ジャッジ時間 40,963 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
75,984 KB
testcase_01 AC 108 ms
76,272 KB
testcase_02 AC 100 ms
76,124 KB
testcase_03 AC 108 ms
76,040 KB
testcase_04 AC 111 ms
75,864 KB
testcase_05 AC 112 ms
76,116 KB
testcase_06 AC 106 ms
76,260 KB
testcase_07 AC 104 ms
76,236 KB
testcase_08 AC 104 ms
76,256 KB
testcase_09 WA -
testcase_10 AC 107 ms
76,136 KB
testcase_11 AC 105 ms
76,240 KB
testcase_12 AC 101 ms
76,104 KB
testcase_13 AC 106 ms
75,744 KB
testcase_14 AC 106 ms
76,152 KB
testcase_15 AC 105 ms
76,256 KB
testcase_16 AC 104 ms
76,044 KB
testcase_17 AC 108 ms
76,068 KB
testcase_18 AC 107 ms
76,112 KB
testcase_19 AC 105 ms
76,136 KB
testcase_20 AC 104 ms
76,048 KB
testcase_21 AC 108 ms
76,060 KB
testcase_22 AC 105 ms
76,044 KB
testcase_23 AC 106 ms
76,280 KB
testcase_24 AC 109 ms
76,344 KB
testcase_25 WA -
testcase_26 AC 105 ms
75,984 KB
testcase_27 WA -
testcase_28 AC 106 ms
76,284 KB
testcase_29 AC 107 ms
75,940 KB
testcase_30 WA -
testcase_31 AC 109 ms
76,168 KB
testcase_32 AC 108 ms
76,124 KB
testcase_33 WA -
testcase_34 AC 106 ms
76,920 KB
testcase_35 WA -
testcase_36 AC 107 ms
76,020 KB
testcase_37 AC 106 ms
76,136 KB
testcase_38 AC 106 ms
76,244 KB
testcase_39 AC 106 ms
76,012 KB
testcase_40 AC 112 ms
76,852 KB
testcase_41 WA -
testcase_42 AC 109 ms
76,064 KB
testcase_43 AC 125 ms
77,752 KB
testcase_44 WA -
testcase_45 AC 114 ms
77,616 KB
testcase_46 WA -
testcase_47 AC 117 ms
77,588 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 121 ms
77,636 KB
testcase_53 AC 126 ms
77,568 KB
testcase_54 AC 132 ms
79,348 KB
testcase_55 AC 126 ms
77,724 KB
testcase_56 WA -
testcase_57 AC 120 ms
77,732 KB
testcase_58 AC 121 ms
77,944 KB
testcase_59 AC 106 ms
76,724 KB
testcase_60 AC 113 ms
77,520 KB
testcase_61 WA -
testcase_62 AC 105 ms
76,744 KB
testcase_63 WA -
testcase_64 AC 140 ms
79,680 KB
testcase_65 WA -
testcase_66 AC 157 ms
80,180 KB
testcase_67 WA -
testcase_68 AC 152 ms
80,640 KB
testcase_69 AC 160 ms
81,768 KB
testcase_70 AC 149 ms
80,116 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 138 ms
79,772 KB
testcase_74 AC 153 ms
80,456 KB
testcase_75 AC 156 ms
80,188 KB
testcase_76 WA -
testcase_77 AC 149 ms
80,244 KB
testcase_78 AC 157 ms
81,740 KB
testcase_79 AC 164 ms
81,852 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 163 ms
81,576 KB
testcase_83 WA -
testcase_84 WA -
testcase_85 AC 308 ms
105,160 KB
testcase_86 AC 420 ms
125,336 KB
testcase_87 AC 510 ms
151,532 KB
testcase_88 AC 168 ms
84,708 KB
testcase_89 AC 532 ms
152,832 KB
testcase_90 WA -
testcase_91 AC 298 ms
104,464 KB
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 AC 498 ms
143,376 KB
testcase_97 AC 252 ms
97,568 KB
testcase_98 WA -
testcase_99 AC 342 ms
113,320 KB
testcase_100 AC 575 ms
162,720 KB
testcase_101 AC 190 ms
87,072 KB
testcase_102 WA -
testcase_103 AC 199 ms
88,648 KB
testcase_104 WA -
testcase_105 WA -
testcase_106 AC 281 ms
99,616 KB
testcase_107 AC 558 ms
159,328 KB
testcase_108 AC 531 ms
147,712 KB
testcase_109 AC 361 ms
113,876 KB
testcase_110 AC 396 ms
121,264 KB
testcase_111 AC 393 ms
120,472 KB
testcase_112 AC 237 ms
93,308 KB
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 AC 317 ms
108,732 KB
testcase_117 WA -
testcase_118 WA -
testcase_119 AC 322 ms
109,208 KB
testcase_120 AC 500 ms
139,336 KB
testcase_121 WA -
testcase_122 WA -
testcase_123 AC 103 ms
76,164 KB
testcase_124 WA -
testcase_125 WA -
権限があれば一括ダウンロードができます

ソースコード

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<3*N:
      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 w==start:
          dic = copy(es)
          dic[i] = True
          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
        if w not in es:
          dic = copy(es)
          dic[i] = True
          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