結果
問題 | No.1254 補強への架け橋 |
ユーザー | marroncastle |
提出日時 | 2020-10-10 02:50:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 1,713 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 153,304 KB |
最終ジャッジ日時 | 2024-07-20 15:32:04 |
合計ジャッジ時間 | 23,541 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
60,032 KB |
testcase_01 | AC | 49 ms
59,904 KB |
testcase_02 | AC | 53 ms
60,032 KB |
testcase_03 | AC | 52 ms
59,904 KB |
testcase_04 | AC | 51 ms
60,544 KB |
testcase_05 | AC | 51 ms
60,288 KB |
testcase_06 | AC | 51 ms
60,544 KB |
testcase_07 | AC | 52 ms
60,160 KB |
testcase_08 | AC | 51 ms
60,288 KB |
testcase_09 | AC | 49 ms
60,288 KB |
testcase_10 | AC | 49 ms
59,904 KB |
testcase_11 | AC | 49 ms
60,032 KB |
testcase_12 | AC | 50 ms
60,032 KB |
testcase_13 | AC | 51 ms
60,288 KB |
testcase_14 | AC | 53 ms
60,416 KB |
testcase_15 | AC | 51 ms
60,672 KB |
testcase_16 | AC | 50 ms
60,160 KB |
testcase_17 | AC | 52 ms
60,544 KB |
testcase_18 | AC | 52 ms
60,032 KB |
testcase_19 | AC | 51 ms
59,904 KB |
testcase_20 | AC | 52 ms
60,416 KB |
testcase_21 | AC | 53 ms
60,160 KB |
testcase_22 | AC | 51 ms
60,160 KB |
testcase_23 | AC | 50 ms
60,672 KB |
testcase_24 | AC | 53 ms
60,416 KB |
testcase_25 | AC | 54 ms
60,160 KB |
testcase_26 | AC | 54 ms
60,416 KB |
testcase_27 | AC | 52 ms
60,160 KB |
testcase_28 | AC | 52 ms
60,544 KB |
testcase_29 | AC | 51 ms
60,160 KB |
testcase_30 | AC | 52 ms
60,160 KB |
testcase_31 | AC | 52 ms
60,416 KB |
testcase_32 | AC | 52 ms
60,672 KB |
testcase_33 | AC | 52 ms
60,288 KB |
testcase_34 | AC | 51 ms
60,544 KB |
testcase_35 | AC | 51 ms
60,288 KB |
testcase_36 | AC | 50 ms
60,416 KB |
testcase_37 | AC | 52 ms
60,544 KB |
testcase_38 | AC | 52 ms
60,160 KB |
testcase_39 | AC | 51 ms
60,288 KB |
testcase_40 | AC | 50 ms
60,032 KB |
testcase_41 | AC | 51 ms
60,672 KB |
testcase_42 | AC | 52 ms
60,928 KB |
testcase_43 | AC | 59 ms
63,872 KB |
testcase_44 | AC | 54 ms
61,568 KB |
testcase_45 | AC | 53 ms
61,312 KB |
testcase_46 | AC | 57 ms
62,464 KB |
testcase_47 | AC | 58 ms
62,080 KB |
testcase_48 | AC | 54 ms
62,464 KB |
testcase_49 | AC | 50 ms
60,416 KB |
testcase_50 | AC | 58 ms
64,128 KB |
testcase_51 | AC | 60 ms
63,872 KB |
testcase_52 | AC | 59 ms
64,512 KB |
testcase_53 | AC | 58 ms
63,360 KB |
testcase_54 | AC | 60 ms
64,384 KB |
testcase_55 | AC | 59 ms
62,208 KB |
testcase_56 | AC | 52 ms
60,544 KB |
testcase_57 | AC | 58 ms
62,464 KB |
testcase_58 | AC | 56 ms
62,464 KB |
testcase_59 | AC | 52 ms
60,928 KB |
testcase_60 | AC | 54 ms
60,928 KB |
testcase_61 | AC | 61 ms
63,488 KB |
testcase_62 | AC | 54 ms
60,544 KB |
testcase_63 | AC | 123 ms
82,304 KB |
testcase_64 | AC | 95 ms
78,080 KB |
testcase_65 | AC | 114 ms
80,384 KB |
testcase_66 | AC | 113 ms
79,744 KB |
testcase_67 | AC | 81 ms
74,624 KB |
testcase_68 | AC | 115 ms
80,000 KB |
testcase_69 | AC | 123 ms
80,640 KB |
testcase_70 | AC | 101 ms
77,824 KB |
testcase_71 | AC | 93 ms
78,080 KB |
testcase_72 | AC | 120 ms
81,408 KB |
testcase_73 | AC | 91 ms
77,312 KB |
testcase_74 | AC | 118 ms
80,256 KB |
testcase_75 | AC | 117 ms
78,848 KB |
testcase_76 | AC | 69 ms
68,480 KB |
testcase_77 | AC | 104 ms
78,720 KB |
testcase_78 | AC | 111 ms
80,896 KB |
testcase_79 | AC | 115 ms
82,432 KB |
testcase_80 | AC | 115 ms
80,640 KB |
testcase_81 | AC | 129 ms
81,536 KB |
testcase_82 | AC | 124 ms
81,280 KB |
testcase_83 | AC | 332 ms
121,276 KB |
testcase_84 | AC | 287 ms
113,244 KB |
testcase_85 | AC | 202 ms
99,976 KB |
testcase_86 | AC | 256 ms
110,048 KB |
testcase_87 | AC | 282 ms
110,816 KB |
testcase_88 | AC | 128 ms
84,096 KB |
testcase_89 | AC | 299 ms
118,384 KB |
testcase_90 | AC | 240 ms
107,572 KB |
testcase_91 | AC | 199 ms
96,488 KB |
testcase_92 | AC | 162 ms
93,056 KB |
testcase_93 | AC | 244 ms
109,028 KB |
testcase_94 | AC | 229 ms
109,440 KB |
testcase_95 | AC | 233 ms
108,548 KB |
testcase_96 | AC | 276 ms
112,860 KB |
testcase_97 | AC | 175 ms
95,488 KB |
testcase_98 | AC | 290 ms
113,136 KB |
testcase_99 | AC | 205 ms
99,712 KB |
testcase_100 | AC | 301 ms
121,512 KB |
testcase_101 | AC | 146 ms
92,416 KB |
testcase_102 | AC | 125 ms
83,328 KB |
testcase_103 | AC | 156 ms
92,800 KB |
testcase_104 | AC | 167 ms
93,824 KB |
testcase_105 | AC | 260 ms
108,784 KB |
testcase_106 | AC | 186 ms
95,872 KB |
testcase_107 | AC | 298 ms
118,132 KB |
testcase_108 | AC | 315 ms
116,344 KB |
testcase_109 | AC | 258 ms
109,412 KB |
testcase_110 | AC | 260 ms
108,496 KB |
testcase_111 | AC | 244 ms
109,268 KB |
testcase_112 | AC | 163 ms
93,440 KB |
testcase_113 | AC | 243 ms
108,868 KB |
testcase_114 | AC | 172 ms
95,136 KB |
testcase_115 | AC | 126 ms
85,120 KB |
testcase_116 | AC | 183 ms
97,024 KB |
testcase_117 | AC | 159 ms
94,848 KB |
testcase_118 | AC | 272 ms
112,660 KB |
testcase_119 | AC | 195 ms
100,108 KB |
testcase_120 | AC | 289 ms
110,404 KB |
testcase_121 | AC | 149 ms
94,336 KB |
testcase_122 | AC | 189 ms
97,512 KB |
testcase_123 | AC | 50 ms
60,032 KB |
testcase_124 | AC | 431 ms
152,900 KB |
testcase_125 | AC | 429 ms
153,304 KB |
ソースコード
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.prev = [N]*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 bfs(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 v,u self.parent[u]=v #頂点に対する処理 stack.append(u) return 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) v,u = G.bfs(0) lis = [] lis.append(G.edges[v,u]) while G.parent[v]!=-1: lis.append(G.edges[(G.parent[v],v)]) v = G.parent[v] while G.parent[u]!=-1: lis.append(G.edges[(G.parent[u],u)]) u = G.parent[u] lis.sort() ans = set() from collections import Counter c = Counter(lis) for k,val in c.items(): if val==1: ans.add(k) print(len(ans)) print(*ans)