結果
問題 | No.1254 補強への架け橋 |
ユーザー | marroncastle |
提出日時 | 2020-10-10 01:36:30 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,985 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 81,756 KB |
実行使用メモリ | 282,908 KB |
最終ジャッジ日時 | 2024-07-20 15:17:37 |
合計ジャッジ時間 | 35,182 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
65,664 KB |
testcase_01 | AC | 50 ms
60,672 KB |
testcase_02 | AC | 49 ms
60,544 KB |
testcase_03 | AC | 50 ms
60,416 KB |
testcase_04 | AC | 55 ms
60,672 KB |
testcase_05 | AC | 54 ms
60,160 KB |
testcase_06 | AC | 50 ms
60,416 KB |
testcase_07 | AC | 53 ms
60,928 KB |
testcase_08 | AC | 51 ms
60,544 KB |
testcase_09 | AC | 49 ms
60,544 KB |
testcase_10 | AC | 49 ms
60,928 KB |
testcase_11 | AC | 50 ms
60,416 KB |
testcase_12 | AC | 50 ms
60,800 KB |
testcase_13 | AC | 50 ms
60,928 KB |
testcase_14 | AC | 53 ms
61,312 KB |
testcase_15 | AC | 51 ms
60,672 KB |
testcase_16 | AC | 50 ms
60,800 KB |
testcase_17 | AC | 51 ms
60,672 KB |
testcase_18 | AC | 50 ms
60,544 KB |
testcase_19 | AC | 50 ms
60,544 KB |
testcase_20 | AC | 50 ms
60,800 KB |
testcase_21 | AC | 51 ms
60,800 KB |
testcase_22 | AC | 51 ms
61,056 KB |
testcase_23 | AC | 50 ms
61,056 KB |
testcase_24 | AC | 54 ms
60,928 KB |
testcase_25 | AC | 50 ms
60,544 KB |
testcase_26 | AC | 51 ms
60,928 KB |
testcase_27 | AC | 51 ms
61,184 KB |
testcase_28 | AC | 50 ms
61,568 KB |
testcase_29 | AC | 51 ms
60,800 KB |
testcase_30 | AC | 50 ms
60,672 KB |
testcase_31 | AC | 50 ms
60,928 KB |
testcase_32 | AC | 52 ms
60,672 KB |
testcase_33 | AC | 52 ms
60,928 KB |
testcase_34 | AC | 50 ms
60,928 KB |
testcase_35 | AC | 51 ms
61,056 KB |
testcase_36 | AC | 50 ms
60,928 KB |
testcase_37 | AC | 50 ms
60,928 KB |
testcase_38 | AC | 56 ms
61,184 KB |
testcase_39 | AC | 51 ms
60,672 KB |
testcase_40 | AC | 51 ms
60,928 KB |
testcase_41 | AC | 51 ms
60,672 KB |
testcase_42 | AC | 50 ms
60,544 KB |
testcase_43 | AC | 75 ms
73,344 KB |
testcase_44 | AC | 58 ms
64,384 KB |
testcase_45 | AC | 56 ms
64,512 KB |
testcase_46 | AC | 76 ms
69,888 KB |
testcase_47 | AC | 62 ms
67,200 KB |
testcase_48 | AC | 67 ms
68,864 KB |
testcase_49 | AC | 52 ms
61,184 KB |
testcase_50 | AC | 73 ms
72,960 KB |
testcase_51 | AC | 72 ms
72,320 KB |
testcase_52 | AC | 72 ms
72,448 KB |
testcase_53 | AC | 72 ms
72,064 KB |
testcase_54 | AC | 71 ms
72,320 KB |
testcase_55 | AC | 70 ms
70,528 KB |
testcase_56 | AC | 56 ms
61,440 KB |
testcase_57 | AC | 66 ms
68,480 KB |
testcase_58 | AC | 68 ms
70,016 KB |
testcase_59 | AC | 52 ms
61,312 KB |
testcase_60 | AC | 57 ms
65,024 KB |
testcase_61 | AC | 71 ms
72,192 KB |
testcase_62 | AC | 52 ms
61,696 KB |
testcase_63 | AC | 154 ms
84,352 KB |
testcase_64 | AC | 106 ms
78,080 KB |
testcase_65 | AC | 141 ms
82,048 KB |
testcase_66 | AC | 132 ms
80,512 KB |
testcase_67 | AC | 96 ms
77,824 KB |
testcase_68 | AC | 131 ms
81,600 KB |
testcase_69 | AC | 141 ms
82,432 KB |
testcase_70 | AC | 110 ms
78,336 KB |
testcase_71 | AC | 104 ms
78,164 KB |
testcase_72 | AC | 141 ms
82,816 KB |
testcase_73 | AC | 97 ms
78,204 KB |
testcase_74 | AC | 135 ms
82,432 KB |
testcase_75 | AC | 134 ms
80,896 KB |
testcase_76 | AC | 84 ms
77,820 KB |
testcase_77 | AC | 121 ms
80,256 KB |
testcase_78 | AC | 147 ms
83,872 KB |
testcase_79 | AC | 153 ms
83,884 KB |
testcase_80 | AC | 146 ms
83,200 KB |
testcase_81 | AC | 155 ms
83,712 KB |
testcase_82 | AC | 151 ms
82,944 KB |
testcase_83 | AC | 667 ms
201,144 KB |
testcase_84 | AC | 620 ms
191,768 KB |
testcase_85 | AC | 352 ms
112,192 KB |
testcase_86 | AC | 499 ms
143,644 KB |
testcase_87 | AC | 594 ms
182,468 KB |
testcase_88 | AC | 168 ms
86,912 KB |
testcase_89 | AC | 621 ms
185,180 KB |
testcase_90 | AC | 396 ms
122,152 KB |
testcase_91 | AC | 339 ms
111,860 KB |
testcase_92 | AC | 237 ms
96,240 KB |
testcase_93 | AC | 421 ms
122,952 KB |
testcase_94 | AC | 469 ms
146,312 KB |
testcase_95 | AC | 461 ms
140,884 KB |
testcase_96 | AC | 593 ms
174,280 KB |
testcase_97 | AC | 298 ms
104,564 KB |
testcase_98 | AC | 600 ms
177,836 KB |
testcase_99 | AC | 370 ms
126,960 KB |
testcase_100 | AC | 609 ms
199,720 KB |
testcase_101 | AC | 212 ms
92,544 KB |
testcase_102 | AC | 168 ms
85,120 KB |
testcase_103 | AC | 222 ms
92,800 KB |
testcase_104 | AC | 228 ms
94,392 KB |
testcase_105 | AC | 483 ms
141,296 KB |
testcase_106 | AC | 304 ms
103,908 KB |
testcase_107 | AC | 625 ms
194,276 KB |
testcase_108 | AC | 594 ms
174,480 KB |
testcase_109 | AC | 407 ms
127,144 KB |
testcase_110 | AC | 440 ms
137,360 KB |
testcase_111 | AC | 460 ms
137,512 KB |
testcase_112 | AC | 243 ms
96,952 KB |
testcase_113 | AC | 453 ms
151,036 KB |
testcase_114 | AC | 258 ms
99,312 KB |
testcase_115 | AC | 170 ms
87,280 KB |
testcase_116 | AC | 347 ms
117,876 KB |
testcase_117 | AC | 254 ms
99,368 KB |
testcase_118 | AC | 527 ms
155,152 KB |
testcase_119 | AC | 377 ms
118,860 KB |
testcase_120 | AC | 562 ms
162,692 KB |
testcase_121 | AC | 213 ms
94,776 KB |
testcase_122 | AC | 350 ms
111,704 KB |
testcase_123 | AC | 51 ms
60,544 KB |
testcase_124 | TLE | - |
testcase_125 | -- | - |
ソースコード
import sys,os,io input = sys.stdin.readline from collections import defaultdict class Graph: def __init__(self, N): self.V = N self.edge = [[] for _ in range(self.V)] self.edges = defaultdict(lambda: 0) self.visited = [0]*N self.parent = [N]*N def add_edge(self, a, b, i): self.edge[a].append(b) self.edges[(a,b)] = i 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 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([[start],{start:True}]) cyc = [] cnt = 0 while len(d)>0 and cnt<N*2+1: vs, tf = d.popleft() for w in self.edge[vs[-1]]: if len(vs)>1 and w==vs[-2]: continue lis,dic = copy(vs), copy(tf) lis.append(w) dic[w] = True if w==start and len(lis)>len(cyc): cyc = lis elif w not in tf: d.append([lis,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()) a,b = min(a-1,b-1), max(a-1,b-1) G.add_edge(a,b,i+1) G.add_edge(b,a,i+1) ans = set() cyc = G.bfs1(0) vs = G.bfs(cyc) for v0,v1 in zip(vs[:-1],vs[1:]): ans.add(G.edges[(v0,v1)]) ans = list(ans) print(len(ans)) print(*ans)