結果
問題 | No.1254 補強への架け橋 |
ユーザー | yuusanlondon |
提出日時 | 2020-10-09 22:51:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 718 ms / 2,000 ms |
コード長 | 3,052 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 200,320 KB |
最終ジャッジ日時 | 2024-07-20 13:23:27 |
合計ジャッジ時間 | 26,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
53,376 KB |
testcase_01 | AC | 46 ms
53,632 KB |
testcase_02 | AC | 45 ms
53,504 KB |
testcase_03 | AC | 45 ms
53,888 KB |
testcase_04 | AC | 44 ms
53,760 KB |
testcase_05 | AC | 45 ms
53,760 KB |
testcase_06 | AC | 45 ms
53,376 KB |
testcase_07 | AC | 45 ms
53,760 KB |
testcase_08 | AC | 45 ms
53,632 KB |
testcase_09 | AC | 46 ms
53,632 KB |
testcase_10 | AC | 45 ms
53,632 KB |
testcase_11 | AC | 45 ms
53,760 KB |
testcase_12 | AC | 45 ms
53,760 KB |
testcase_13 | AC | 46 ms
53,888 KB |
testcase_14 | AC | 45 ms
54,144 KB |
testcase_15 | AC | 48 ms
53,888 KB |
testcase_16 | AC | 44 ms
54,016 KB |
testcase_17 | AC | 46 ms
53,632 KB |
testcase_18 | AC | 46 ms
54,016 KB |
testcase_19 | AC | 45 ms
53,632 KB |
testcase_20 | AC | 46 ms
54,272 KB |
testcase_21 | AC | 46 ms
53,760 KB |
testcase_22 | AC | 45 ms
54,144 KB |
testcase_23 | AC | 46 ms
53,888 KB |
testcase_24 | AC | 47 ms
54,272 KB |
testcase_25 | AC | 47 ms
54,144 KB |
testcase_26 | AC | 48 ms
53,760 KB |
testcase_27 | AC | 47 ms
53,888 KB |
testcase_28 | AC | 46 ms
54,016 KB |
testcase_29 | AC | 46 ms
53,888 KB |
testcase_30 | AC | 45 ms
53,632 KB |
testcase_31 | AC | 48 ms
54,144 KB |
testcase_32 | AC | 46 ms
53,760 KB |
testcase_33 | AC | 47 ms
54,144 KB |
testcase_34 | AC | 46 ms
54,016 KB |
testcase_35 | AC | 48 ms
54,400 KB |
testcase_36 | AC | 47 ms
53,760 KB |
testcase_37 | AC | 47 ms
54,144 KB |
testcase_38 | AC | 46 ms
54,400 KB |
testcase_39 | AC | 47 ms
53,888 KB |
testcase_40 | AC | 47 ms
54,272 KB |
testcase_41 | AC | 45 ms
53,760 KB |
testcase_42 | AC | 47 ms
53,760 KB |
testcase_43 | AC | 67 ms
64,768 KB |
testcase_44 | AC | 53 ms
55,808 KB |
testcase_45 | AC | 52 ms
55,808 KB |
testcase_46 | AC | 67 ms
64,768 KB |
testcase_47 | AC | 55 ms
56,704 KB |
testcase_48 | AC | 71 ms
66,560 KB |
testcase_49 | AC | 47 ms
54,400 KB |
testcase_50 | AC | 74 ms
66,944 KB |
testcase_51 | AC | 74 ms
67,072 KB |
testcase_52 | AC | 77 ms
69,248 KB |
testcase_53 | AC | 67 ms
65,280 KB |
testcase_54 | AC | 75 ms
68,736 KB |
testcase_55 | AC | 66 ms
64,128 KB |
testcase_56 | AC | 49 ms
54,656 KB |
testcase_57 | AC | 62 ms
62,720 KB |
testcase_58 | AC | 61 ms
62,208 KB |
testcase_59 | AC | 48 ms
54,656 KB |
testcase_60 | AC | 52 ms
55,168 KB |
testcase_61 | AC | 66 ms
63,872 KB |
testcase_62 | AC | 48 ms
54,528 KB |
testcase_63 | AC | 137 ms
80,256 KB |
testcase_64 | AC | 118 ms
77,568 KB |
testcase_65 | AC | 129 ms
78,080 KB |
testcase_66 | AC | 140 ms
78,848 KB |
testcase_67 | AC | 110 ms
77,568 KB |
testcase_68 | AC | 127 ms
77,440 KB |
testcase_69 | AC | 139 ms
79,104 KB |
testcase_70 | AC | 123 ms
78,208 KB |
testcase_71 | AC | 110 ms
77,312 KB |
testcase_72 | AC | 126 ms
77,568 KB |
testcase_73 | AC | 118 ms
77,440 KB |
testcase_74 | AC | 126 ms
77,568 KB |
testcase_75 | AC | 136 ms
78,080 KB |
testcase_76 | AC | 90 ms
74,368 KB |
testcase_77 | AC | 127 ms
78,336 KB |
testcase_78 | AC | 148 ms
80,000 KB |
testcase_79 | AC | 136 ms
78,976 KB |
testcase_80 | AC | 136 ms
79,232 KB |
testcase_81 | AC | 135 ms
79,232 KB |
testcase_82 | AC | 133 ms
78,720 KB |
testcase_83 | AC | 345 ms
103,680 KB |
testcase_84 | AC | 336 ms
101,120 KB |
testcase_85 | AC | 245 ms
94,336 KB |
testcase_86 | AC | 316 ms
98,048 KB |
testcase_87 | AC | 347 ms
100,608 KB |
testcase_88 | AC | 147 ms
81,280 KB |
testcase_89 | AC | 349 ms
103,168 KB |
testcase_90 | AC | 254 ms
93,056 KB |
testcase_91 | AC | 228 ms
90,880 KB |
testcase_92 | AC | 171 ms
85,632 KB |
testcase_93 | AC | 286 ms
97,280 KB |
testcase_94 | AC | 266 ms
95,360 KB |
testcase_95 | AC | 269 ms
95,744 KB |
testcase_96 | AC | 325 ms
100,736 KB |
testcase_97 | AC | 215 ms
87,808 KB |
testcase_98 | AC | 357 ms
100,992 KB |
testcase_99 | AC | 242 ms
92,800 KB |
testcase_100 | AC | 370 ms
102,912 KB |
testcase_101 | AC | 187 ms
84,736 KB |
testcase_102 | AC | 149 ms
80,384 KB |
testcase_103 | AC | 177 ms
86,272 KB |
testcase_104 | AC | 203 ms
85,760 KB |
testcase_105 | AC | 312 ms
97,536 KB |
testcase_106 | AC | 218 ms
89,216 KB |
testcase_107 | AC | 340 ms
103,168 KB |
testcase_108 | AC | 336 ms
102,528 KB |
testcase_109 | AC | 296 ms
97,024 KB |
testcase_110 | AC | 282 ms
96,000 KB |
testcase_111 | AC | 286 ms
95,616 KB |
testcase_112 | AC | 199 ms
85,760 KB |
testcase_113 | AC | 275 ms
95,744 KB |
testcase_114 | AC | 220 ms
88,320 KB |
testcase_115 | AC | 150 ms
81,792 KB |
testcase_116 | AC | 230 ms
91,008 KB |
testcase_117 | AC | 185 ms
85,376 KB |
testcase_118 | AC | 344 ms
100,864 KB |
testcase_119 | AC | 241 ms
93,056 KB |
testcase_120 | AC | 316 ms
100,992 KB |
testcase_121 | AC | 185 ms
85,888 KB |
testcase_122 | AC | 226 ms
91,008 KB |
testcase_123 | AC | 46 ms
53,632 KB |
testcase_124 | AC | 718 ms
200,320 KB |
testcase_125 | AC | 701 ms
199,936 KB |
ソースコード
# Python program to find bridges in a given undirected graph #Complexity : O(V+E) import sys from collections import defaultdict sys.setrecursionlimit(10**6) #This class represents an undirected graph using adjacency list representation class Graph: def __init__(self,vertices): self.V= vertices #No. of vertices self.graph = defaultdict(list) # default dictionary to store graph self.Time = 0 # function to add an edge to graph def addEdge(self,u,v,i): self.graph[u].append((v,i)) self.graph[v].append((u,i)) '''A recursive function that finds and prints bridges using DFS traversal u --> The vertex to be visited next visited[] --> keeps tract of visited vertices disc[] --> Stores discovery times of visited vertices parent[] --> Stores parent vertices in DFS tree''' def bridgeUtil(self,u, visited, parent, low, disc): global bridges # Mark the current node as visited and print it visited[u]= True # Initialize discovery time and low value disc[u] = self.Time low[u] = self.Time self.Time += 1 #Recur for all the vertices adjacent to this vertex for (v,i) in self.graph[u]: # If v is not visited yet, then make it a child of u # in DFS tree and recur for it if visited[v] == False : parent[v] = u self.bridgeUtil(v, visited, parent, low, disc) # Check if the subtree rooted with v has a connection to # one of the ancestors of u low[u] = min(low[u], low[v]) ''' If the lowest vertex reachable from subtree under v is below u in DFS tree, then u-v is a bridge''' if low[v] > disc[u]: bridges[i]=1 elif v != parent[u]: # Update low value of u for parent function calls. low[u] = min(low[u], disc[v]) # DFS based function to find all bridges. It uses recursive # function bridgeUtil() def bridge(self): global bridges # Mark all the vertices as not visited and Initialize parent and visited, # and ap(articulation point) arrays visited = [False] * (self.V) disc = [float("Inf")] * (self.V) low = [float("Inf")] * (self.V) parent = [-1] * (self.V) # Call the recursive helper function to find bridges # in DFS tree rooted with vertex 'i' for i in range(self.V): if visited[i] == False: self.bridgeUtil(i, visited, parent, low, disc) n=int(input()) # Create a graph given in the above diagram g1 = Graph(n) bridges=[0]*n for i in range(n): a,b=map(int,input().split()) g1.addEdge(a-1,b-1, i) g1.bridge() ans=[] for i in range(n): if bridges[i]==0: ans.append(str(i+1)) print(len(ans)) print(' '.join(ans))