結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
76,228 KB
testcase_01 AC 110 ms
76,236 KB
testcase_02 AC 112 ms
76,108 KB
testcase_03 AC 110 ms
75,868 KB
testcase_04 AC 111 ms
76,196 KB
testcase_05 AC 110 ms
76,072 KB
testcase_06 AC 110 ms
76,148 KB
testcase_07 AC 111 ms
76,152 KB
testcase_08 AC 111 ms
76,276 KB
testcase_09 AC 113 ms
76,112 KB
testcase_10 AC 111 ms
76,172 KB
testcase_11 AC 112 ms
76,176 KB
testcase_12 AC 112 ms
76,264 KB
testcase_13 AC 114 ms
76,192 KB
testcase_14 AC 112 ms
76,248 KB
testcase_15 AC 113 ms
75,880 KB
testcase_16 AC 111 ms
75,884 KB
testcase_17 AC 113 ms
75,880 KB
testcase_18 AC 111 ms
75,880 KB
testcase_19 AC 111 ms
76,088 KB
testcase_20 AC 110 ms
76,108 KB
testcase_21 AC 112 ms
76,108 KB
testcase_22 AC 110 ms
76,276 KB
testcase_23 AC 110 ms
76,140 KB
testcase_24 AC 112 ms
76,196 KB
testcase_25 AC 109 ms
76,136 KB
testcase_26 AC 114 ms
76,844 KB
testcase_27 AC 112 ms
76,296 KB
testcase_28 AC 113 ms
76,092 KB
testcase_29 AC 111 ms
76,136 KB
testcase_30 AC 117 ms
76,068 KB
testcase_31 AC 113 ms
76,248 KB
testcase_32 AC 112 ms
76,176 KB
testcase_33 AC 114 ms
76,788 KB
testcase_34 AC 113 ms
76,900 KB
testcase_35 AC 113 ms
76,268 KB
testcase_36 AC 117 ms
76,736 KB
testcase_37 AC 112 ms
76,292 KB
testcase_38 AC 113 ms
76,232 KB
testcase_39 AC 111 ms
76,260 KB
testcase_40 AC 114 ms
76,176 KB
testcase_41 AC 112 ms
76,312 KB
testcase_42 AC 115 ms
76,188 KB
testcase_43 AC 135 ms
77,964 KB
testcase_44 AC 121 ms
77,540 KB
testcase_45 AC 120 ms
77,808 KB
testcase_46 AC 126 ms
77,672 KB
testcase_47 AC 124 ms
77,528 KB
testcase_48 AC 128 ms
77,836 KB
testcase_49 AC 115 ms
76,824 KB
testcase_50 AC 131 ms
77,796 KB
testcase_51 AC 131 ms
77,968 KB
testcase_52 AC 130 ms
78,124 KB
testcase_53 AC 128 ms
77,944 KB
testcase_54 AC 132 ms
77,920 KB
testcase_55 AC 128 ms
78,092 KB
testcase_56 AC 115 ms
76,828 KB
testcase_57 AC 125 ms
77,760 KB
testcase_58 AC 130 ms
78,152 KB
testcase_59 AC 115 ms
76,832 KB
testcase_60 AC 121 ms
77,536 KB
testcase_61 AC 131 ms
77,932 KB
testcase_62 AC 117 ms
76,796 KB
testcase_63 AC 188 ms
81,924 KB
testcase_64 AC 158 ms
79,852 KB
testcase_65 AC 172 ms
81,388 KB
testcase_66 AC 164 ms
80,168 KB
testcase_67 AC 150 ms
79,564 KB
testcase_68 AC 165 ms
80,788 KB
testcase_69 AC 177 ms
81,520 KB
testcase_70 AC 161 ms
80,104 KB
testcase_71 AC 156 ms
79,756 KB
testcase_72 AC 180 ms
81,776 KB
testcase_73 AC 152 ms
79,752 KB
testcase_74 AC 163 ms
80,480 KB
testcase_75 AC 166 ms
80,180 KB
testcase_76 AC 141 ms
79,900 KB
testcase_77 AC 165 ms
80,456 KB
testcase_78 AC 177 ms
82,048 KB
testcase_79 AC 187 ms
81,964 KB
testcase_80 AC 177 ms
81,600 KB
testcase_81 AC 180 ms
81,764 KB
testcase_82 AC 176 ms
81,508 KB
testcase_83 AC 667 ms
161,676 KB
testcase_84 AC 638 ms
157,204 KB
testcase_85 AC 369 ms
105,132 KB
testcase_86 AC 510 ms
125,448 KB
testcase_87 AC 600 ms
151,876 KB
testcase_88 AC 208 ms
84,312 KB
testcase_89 AC 623 ms
153,096 KB
testcase_90 AC 412 ms
111,804 KB
testcase_91 AC 361 ms
104,580 KB
testcase_92 AC 271 ms
91,556 KB
testcase_93 AC 425 ms
111,204 KB
testcase_94 AC 476 ms
125,296 KB
testcase_95 AC 480 ms
122,524 KB
testcase_96 AC 574 ms
143,472 KB
testcase_97 AC 325 ms
97,536 KB
testcase_98 AC 624 ms
147,780 KB
testcase_99 AC 404 ms
113,308 KB
testcase_100 AC 639 ms
162,860 KB
testcase_101 AC 228 ms
86,988 KB
testcase_102 AC 195 ms
83,332 KB
testcase_103 AC 239 ms
88,560 KB
testcase_104 AC 249 ms
90,756 KB
testcase_105 AC 506 ms
124,056 KB
testcase_106 AC 329 ms
99,560 KB
testcase_107 AC 632 ms
159,320 KB
testcase_108 AC 623 ms
147,740 KB
testcase_109 AC 429 ms
113,968 KB
testcase_110 AC 472 ms
121,352 KB
testcase_111 AC 473 ms
120,440 KB
testcase_112 AC 280 ms
92,920 KB
testcase_113 AC 486 ms
127,712 KB
testcase_114 AC 273 ms
93,452 KB
testcase_115 AC 204 ms
84,996 KB
testcase_116 AC 376 ms
108,832 KB
testcase_117 AC 281 ms
94,052 KB
testcase_118 AC 524 ms
133,128 KB
testcase_119 AC 391 ms
109,556 KB
testcase_120 AC 577 ms
139,424 KB
testcase_121 AC 243 ms
89,396 KB
testcase_122 AC 376 ms
103,852 KB
testcase_123 AC 110 ms
76,100 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<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 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