結果
問題 | No.1254 補強への架け橋 |
ユーザー | marroncastle |
提出日時 | 2020-10-10 02:00:17 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,954 bytes |
コンパイル時間 | 289 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 282,456 KB |
最終ジャッジ日時 | 2024-07-20 15:26:51 |
合計ジャッジ時間 | 30,814 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
65,664 KB |
testcase_01 | AC | 53 ms
60,416 KB |
testcase_02 | AC | 53 ms
60,672 KB |
testcase_03 | AC | 54 ms
60,160 KB |
testcase_04 | AC | 53 ms
60,416 KB |
testcase_05 | AC | 53 ms
60,288 KB |
testcase_06 | AC | 55 ms
60,160 KB |
testcase_07 | AC | 54 ms
60,544 KB |
testcase_08 | AC | 54 ms
60,416 KB |
testcase_09 | AC | 54 ms
60,544 KB |
testcase_10 | AC | 53 ms
60,160 KB |
testcase_11 | AC | 53 ms
60,544 KB |
testcase_12 | AC | 53 ms
60,416 KB |
testcase_13 | AC | 55 ms
60,672 KB |
testcase_14 | AC | 53 ms
60,672 KB |
testcase_15 | AC | 55 ms
60,288 KB |
testcase_16 | AC | 53 ms
60,160 KB |
testcase_17 | AC | 53 ms
60,160 KB |
testcase_18 | AC | 53 ms
60,416 KB |
testcase_19 | AC | 53 ms
60,544 KB |
testcase_20 | AC | 55 ms
60,544 KB |
testcase_21 | AC | 54 ms
60,416 KB |
testcase_22 | AC | 55 ms
60,416 KB |
testcase_23 | AC | 55 ms
60,544 KB |
testcase_24 | AC | 55 ms
60,800 KB |
testcase_25 | AC | 55 ms
60,288 KB |
testcase_26 | AC | 55 ms
60,800 KB |
testcase_27 | AC | 54 ms
60,416 KB |
testcase_28 | AC | 56 ms
60,800 KB |
testcase_29 | AC | 55 ms
60,416 KB |
testcase_30 | AC | 55 ms
60,800 KB |
testcase_31 | AC | 55 ms
60,416 KB |
testcase_32 | AC | 54 ms
60,416 KB |
testcase_33 | AC | 54 ms
60,928 KB |
testcase_34 | AC | 55 ms
61,184 KB |
testcase_35 | AC | 54 ms
60,672 KB |
testcase_36 | AC | 56 ms
60,672 KB |
testcase_37 | AC | 55 ms
60,672 KB |
testcase_38 | AC | 55 ms
60,672 KB |
testcase_39 | AC | 57 ms
60,800 KB |
testcase_40 | AC | 55 ms
60,544 KB |
testcase_41 | AC | 55 ms
60,544 KB |
testcase_42 | AC | 54 ms
60,160 KB |
testcase_43 | AC | 82 ms
71,808 KB |
testcase_44 | AC | 56 ms
61,568 KB |
testcase_45 | AC | 57 ms
61,824 KB |
testcase_46 | AC | 73 ms
67,840 KB |
testcase_47 | AC | 59 ms
62,720 KB |
testcase_48 | AC | 61 ms
62,592 KB |
testcase_49 | AC | 57 ms
60,672 KB |
testcase_50 | AC | 74 ms
69,120 KB |
testcase_51 | AC | 74 ms
68,992 KB |
testcase_52 | AC | 73 ms
69,120 KB |
testcase_53 | AC | 72 ms
68,736 KB |
testcase_54 | AC | 72 ms
68,352 KB |
testcase_55 | AC | 71 ms
67,584 KB |
testcase_56 | AC | 56 ms
61,312 KB |
testcase_57 | AC | 65 ms
65,280 KB |
testcase_58 | AC | 67 ms
66,688 KB |
testcase_59 | AC | 55 ms
60,672 KB |
testcase_60 | AC | 58 ms
62,208 KB |
testcase_61 | AC | 65 ms
65,664 KB |
testcase_62 | AC | 57 ms
61,184 KB |
testcase_63 | AC | 151 ms
84,352 KB |
testcase_64 | AC | 113 ms
78,464 KB |
testcase_65 | AC | 140 ms
82,048 KB |
testcase_66 | AC | 132 ms
80,128 KB |
testcase_67 | AC | 102 ms
78,208 KB |
testcase_68 | AC | 130 ms
80,640 KB |
testcase_69 | AC | 146 ms
82,304 KB |
testcase_70 | AC | 115 ms
78,720 KB |
testcase_71 | AC | 107 ms
77,952 KB |
testcase_72 | AC | 142 ms
83,072 KB |
testcase_73 | AC | 106 ms
78,464 KB |
testcase_74 | AC | 139 ms
82,560 KB |
testcase_75 | AC | 134 ms
80,000 KB |
testcase_76 | AC | 85 ms
74,112 KB |
testcase_77 | AC | 123 ms
79,744 KB |
testcase_78 | AC | 146 ms
83,456 KB |
testcase_79 | AC | 150 ms
84,096 KB |
testcase_80 | AC | 143 ms
82,944 KB |
testcase_81 | AC | 147 ms
83,968 KB |
testcase_82 | AC | 144 ms
83,200 KB |
testcase_83 | AC | 474 ms
135,744 KB |
testcase_84 | AC | 450 ms
134,416 KB |
testcase_85 | AC | 294 ms
104,492 KB |
testcase_86 | AC | 391 ms
117,476 KB |
testcase_87 | AC | 425 ms
126,028 KB |
testcase_88 | AC | 153 ms
87,040 KB |
testcase_89 | AC | 452 ms
133,692 KB |
testcase_90 | AC | 321 ms
107,804 KB |
testcase_91 | AC | 281 ms
100,584 KB |
testcase_92 | AC | 205 ms
93,312 KB |
testcase_93 | AC | 379 ms
117,600 KB |
testcase_94 | AC | 348 ms
114,692 KB |
testcase_95 | AC | 358 ms
113,880 KB |
testcase_96 | AC | 381 ms
122,684 KB |
testcase_97 | AC | 249 ms
98,096 KB |
testcase_98 | AC | 439 ms
127,988 KB |
testcase_99 | AC | 290 ms
104,432 KB |
testcase_100 | AC | 438 ms
135,732 KB |
testcase_101 | AC | 180 ms
92,800 KB |
testcase_102 | AC | 150 ms
84,992 KB |
testcase_103 | AC | 189 ms
93,184 KB |
testcase_104 | AC | 215 ms
94,900 KB |
testcase_105 | AC | 368 ms
118,232 KB |
testcase_106 | AC | 251 ms
99,528 KB |
testcase_107 | AC | 452 ms
131,696 KB |
testcase_108 | AC | 402 ms
123,400 KB |
testcase_109 | AC | 353 ms
118,924 KB |
testcase_110 | AC | 331 ms
112,528 KB |
testcase_111 | AC | 360 ms
118,168 KB |
testcase_112 | AC | 211 ms
94,048 KB |
testcase_113 | AC | 334 ms
111,856 KB |
testcase_114 | AC | 254 ms
99,612 KB |
testcase_115 | AC | 166 ms
87,424 KB |
testcase_116 | AC | 267 ms
101,204 KB |
testcase_117 | AC | 184 ms
94,976 KB |
testcase_118 | AC | 419 ms
126,936 KB |
testcase_119 | AC | 237 ms
104,816 KB |
testcase_120 | AC | 386 ms
120,052 KB |
testcase_121 | AC | 196 ms
94,592 KB |
testcase_122 | AC | 282 ms
101,724 KB |
testcase_123 | AC | 54 ms
60,288 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 = deque([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 = [] length = [0]*self.V while len(d)>0: vs, tf = d.popleft() for w in self.edge[vs[-1]]: if len(vs)>1 and w==vs[-2]: continue cyc,dic = copy(vs), copy(tf) cyc.append(w) dic[w] = True if w==start: return cyc elif w not in tf: d.append([cyc,dic]) 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)