結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 00:47:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 189,300 KB
最終ジャッジ日時 2023-09-27 20:30:50
合計ジャッジ時間 38,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
76,056 KB
testcase_01 AC 113 ms
75,864 KB
testcase_02 AC 111 ms
76,076 KB
testcase_03 AC 112 ms
76,088 KB
testcase_04 AC 113 ms
76,180 KB
testcase_05 AC 113 ms
76,288 KB
testcase_06 AC 114 ms
75,852 KB
testcase_07 AC 114 ms
76,284 KB
testcase_08 AC 115 ms
76,324 KB
testcase_09 WA -
testcase_10 AC 112 ms
76,064 KB
testcase_11 AC 112 ms
76,308 KB
testcase_12 AC 113 ms
76,184 KB
testcase_13 AC 115 ms
76,100 KB
testcase_14 AC 114 ms
76,056 KB
testcase_15 AC 114 ms
75,860 KB
testcase_16 AC 113 ms
76,092 KB
testcase_17 AC 111 ms
76,096 KB
testcase_18 AC 113 ms
75,820 KB
testcase_19 AC 115 ms
76,168 KB
testcase_20 AC 113 ms
76,076 KB
testcase_21 AC 112 ms
76,300 KB
testcase_22 AC 112 ms
76,248 KB
testcase_23 AC 114 ms
76,200 KB
testcase_24 AC 114 ms
76,260 KB
testcase_25 WA -
testcase_26 AC 113 ms
76,096 KB
testcase_27 AC 115 ms
76,268 KB
testcase_28 AC 114 ms
76,136 KB
testcase_29 AC 115 ms
76,168 KB
testcase_30 WA -
testcase_31 AC 114 ms
75,860 KB
testcase_32 AC 113 ms
76,236 KB
testcase_33 WA -
testcase_34 AC 114 ms
76,868 KB
testcase_35 AC 113 ms
76,228 KB
testcase_36 AC 115 ms
76,228 KB
testcase_37 AC 113 ms
75,860 KB
testcase_38 AC 116 ms
76,216 KB
testcase_39 AC 114 ms
76,264 KB
testcase_40 AC 115 ms
76,076 KB
testcase_41 WA -
testcase_42 AC 114 ms
76,080 KB
testcase_43 AC 132 ms
77,804 KB
testcase_44 WA -
testcase_45 AC 120 ms
77,708 KB
testcase_46 WA -
testcase_47 AC 128 ms
77,672 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 136 ms
77,784 KB
testcase_53 AC 133 ms
77,920 KB
testcase_54 AC 133 ms
77,948 KB
testcase_55 AC 128 ms
77,932 KB
testcase_56 WA -
testcase_57 AC 128 ms
77,956 KB
testcase_58 AC 127 ms
77,796 KB
testcase_59 AC 114 ms
77,048 KB
testcase_60 AC 121 ms
77,688 KB
testcase_61 WA -
testcase_62 AC 117 ms
77,004 KB
testcase_63 WA -
testcase_64 AC 157 ms
80,136 KB
testcase_65 WA -
testcase_66 AC 165 ms
80,188 KB
testcase_67 WA -
testcase_68 AC 171 ms
80,800 KB
testcase_69 AC 178 ms
81,680 KB
testcase_70 AC 162 ms
80,108 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 155 ms
80,044 KB
testcase_74 AC 165 ms
80,544 KB
testcase_75 AC 168 ms
80,252 KB
testcase_76 WA -
testcase_77 AC 167 ms
80,356 KB
testcase_78 AC 177 ms
81,720 KB
testcase_79 AC 186 ms
81,876 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 182 ms
81,504 KB
testcase_83 WA -
testcase_84 AC 645 ms
160,928 KB
testcase_85 AC 389 ms
105,160 KB
testcase_86 AC 516 ms
125,508 KB
testcase_87 AC 607 ms
151,516 KB
testcase_88 AC 205 ms
84,540 KB
testcase_89 AC 629 ms
152,824 KB
testcase_90 WA -
testcase_91 AC 370 ms
104,524 KB
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 AC 587 ms
143,364 KB
testcase_97 AC 321 ms
97,480 KB
testcase_98 WA -
testcase_99 AC 414 ms
113,444 KB
testcase_100 AC 653 ms
162,876 KB
testcase_101 AC 232 ms
87,068 KB
testcase_102 AC 197 ms
83,536 KB
testcase_103 AC 243 ms
88,624 KB
testcase_104 WA -
testcase_105 WA -
testcase_106 AC 341 ms
99,560 KB
testcase_107 AC 629 ms
159,284 KB
testcase_108 AC 613 ms
147,696 KB
testcase_109 AC 430 ms
113,952 KB
testcase_110 AC 473 ms
121,136 KB
testcase_111 AC 479 ms
120,420 KB
testcase_112 AC 281 ms
93,092 KB
testcase_113 WA -
testcase_114 WA -
testcase_115 WA -
testcase_116 AC 382 ms
108,736 KB
testcase_117 WA -
testcase_118 WA -
testcase_119 AC 390 ms
109,356 KB
testcase_120 AC 587 ms
139,200 KB
testcase_121 WA -
testcase_122 WA -
testcase_123 AC 114 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<2*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