結果

問題 No.1254 補強への架け橋
ユーザー marroncastlemarroncastle
提出日時 2020-10-10 01:02:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,076 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 278,184 KB
最終ジャッジ日時 2023-09-27 20:36:18
合計ジャッジ時間 40,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
76,092 KB
testcase_01 AC 110 ms
76,220 KB
testcase_02 AC 112 ms
76,108 KB
testcase_03 AC 112 ms
76,104 KB
testcase_04 AC 114 ms
75,756 KB
testcase_05 AC 111 ms
76,272 KB
testcase_06 AC 112 ms
76,036 KB
testcase_07 AC 113 ms
76,176 KB
testcase_08 AC 111 ms
76,192 KB
testcase_09 AC 115 ms
76,184 KB
testcase_10 AC 111 ms
76,256 KB
testcase_11 AC 110 ms
75,992 KB
testcase_12 AC 112 ms
76,092 KB
testcase_13 AC 113 ms
76,124 KB
testcase_14 AC 111 ms
76,036 KB
testcase_15 AC 114 ms
76,292 KB
testcase_16 AC 110 ms
76,104 KB
testcase_17 AC 112 ms
76,228 KB
testcase_18 AC 110 ms
76,104 KB
testcase_19 AC 114 ms
76,184 KB
testcase_20 AC 113 ms
76,040 KB
testcase_21 AC 112 ms
76,288 KB
testcase_22 AC 113 ms
76,292 KB
testcase_23 AC 110 ms
76,216 KB
testcase_24 AC 112 ms
76,264 KB
testcase_25 AC 112 ms
76,188 KB
testcase_26 AC 113 ms
76,884 KB
testcase_27 AC 112 ms
76,172 KB
testcase_28 AC 111 ms
76,180 KB
testcase_29 AC 111 ms
75,876 KB
testcase_30 AC 115 ms
75,992 KB
testcase_31 AC 116 ms
76,096 KB
testcase_32 AC 111 ms
75,788 KB
testcase_33 AC 112 ms
76,832 KB
testcase_34 AC 113 ms
76,808 KB
testcase_35 AC 113 ms
76,300 KB
testcase_36 AC 114 ms
76,840 KB
testcase_37 AC 112 ms
75,824 KB
testcase_38 AC 114 ms
76,096 KB
testcase_39 AC 111 ms
76,184 KB
testcase_40 AC 112 ms
76,040 KB
testcase_41 AC 114 ms
75,792 KB
testcase_42 AC 112 ms
76,016 KB
testcase_43 AC 130 ms
78,116 KB
testcase_44 AC 116 ms
77,692 KB
testcase_45 AC 120 ms
77,752 KB
testcase_46 AC 126 ms
77,976 KB
testcase_47 AC 121 ms
77,528 KB
testcase_48 AC 127 ms
78,092 KB
testcase_49 AC 113 ms
76,872 KB
testcase_50 AC 134 ms
77,784 KB
testcase_51 AC 131 ms
77,964 KB
testcase_52 AC 131 ms
78,140 KB
testcase_53 AC 128 ms
77,984 KB
testcase_54 AC 132 ms
77,924 KB
testcase_55 AC 126 ms
77,908 KB
testcase_56 AC 115 ms
76,700 KB
testcase_57 AC 125 ms
77,840 KB
testcase_58 AC 128 ms
77,800 KB
testcase_59 AC 116 ms
76,712 KB
testcase_60 AC 119 ms
77,628 KB
testcase_61 AC 134 ms
77,976 KB
testcase_62 AC 116 ms
76,748 KB
testcase_63 AC 189 ms
81,800 KB
testcase_64 AC 158 ms
79,660 KB
testcase_65 AC 170 ms
81,184 KB
testcase_66 AC 164 ms
80,144 KB
testcase_67 AC 149 ms
79,432 KB
testcase_68 AC 170 ms
80,712 KB
testcase_69 AC 179 ms
81,392 KB
testcase_70 AC 163 ms
80,124 KB
testcase_71 AC 155 ms
79,916 KB
testcase_72 AC 180 ms
81,636 KB
testcase_73 AC 154 ms
79,796 KB
testcase_74 AC 165 ms
80,336 KB
testcase_75 AC 166 ms
80,096 KB
testcase_76 AC 142 ms
79,728 KB
testcase_77 AC 168 ms
80,248 KB
testcase_78 AC 177 ms
81,628 KB
testcase_79 AC 183 ms
81,896 KB
testcase_80 AC 177 ms
81,556 KB
testcase_81 AC 186 ms
81,764 KB
testcase_82 AC 180 ms
81,576 KB
testcase_83 AC 667 ms
161,264 KB
testcase_84 AC 644 ms
157,148 KB
testcase_85 AC 379 ms
105,192 KB
testcase_86 AC 511 ms
125,372 KB
testcase_87 AC 603 ms
151,436 KB
testcase_88 AC 194 ms
84,284 KB
testcase_89 AC 631 ms
152,724 KB
testcase_90 AC 418 ms
111,764 KB
testcase_91 AC 365 ms
104,676 KB
testcase_92 AC 274 ms
91,508 KB
testcase_93 AC 426 ms
111,168 KB
testcase_94 AC 476 ms
124,972 KB
testcase_95 AC 484 ms
122,736 KB
testcase_96 AC 588 ms
143,240 KB
testcase_97 AC 320 ms
97,408 KB
testcase_98 AC 616 ms
147,652 KB
testcase_99 AC 417 ms
113,348 KB
testcase_100 AC 652 ms
162,820 KB
testcase_101 AC 231 ms
87,208 KB
testcase_102 AC 197 ms
83,308 KB
testcase_103 AC 243 ms
88,560 KB
testcase_104 AC 255 ms
90,452 KB
testcase_105 AC 511 ms
124,008 KB
testcase_106 AC 336 ms
99,480 KB
testcase_107 AC 634 ms
159,368 KB
testcase_108 AC 623 ms
147,704 KB
testcase_109 AC 437 ms
113,908 KB
testcase_110 AC 475 ms
121,228 KB
testcase_111 AC 475 ms
120,288 KB
testcase_112 AC 281 ms
92,756 KB
testcase_113 AC 495 ms
127,596 KB
testcase_114 AC 271 ms
93,616 KB
testcase_115 AC 202 ms
84,696 KB
testcase_116 AC 381 ms
108,852 KB
testcase_117 AC 281 ms
93,832 KB
testcase_118 AC 528 ms
133,120 KB
testcase_119 AC 393 ms
109,420 KB
testcase_120 AC 593 ms
139,148 KB
testcase_121 AC 256 ms
89,540 KB
testcase_122 AC 374 ms
103,812 KB
testcase_123 AC 110 ms
76,092 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<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 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