結果
問題 | No.1254 補強への架け橋 |
ユーザー | yuusanlondon |
提出日時 | 2020-10-09 22:49:35 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,020 bytes |
コンパイル時間 | 92 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 52,600 KB |
最終ジャッジ日時 | 2024-07-20 13:17:15 |
合計ジャッジ時間 | 34,387 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 31 ms
10,880 KB |
testcase_02 | AC | 30 ms
10,880 KB |
testcase_03 | AC | 31 ms
10,880 KB |
testcase_04 | AC | 31 ms
10,752 KB |
testcase_05 | AC | 31 ms
10,880 KB |
testcase_06 | AC | 31 ms
10,880 KB |
testcase_07 | AC | 30 ms
10,752 KB |
testcase_08 | AC | 30 ms
10,752 KB |
testcase_09 | AC | 31 ms
10,752 KB |
testcase_10 | AC | 30 ms
10,880 KB |
testcase_11 | AC | 31 ms
10,752 KB |
testcase_12 | AC | 31 ms
10,752 KB |
testcase_13 | AC | 31 ms
10,880 KB |
testcase_14 | AC | 31 ms
10,880 KB |
testcase_15 | AC | 31 ms
10,624 KB |
testcase_16 | AC | 31 ms
10,880 KB |
testcase_17 | AC | 31 ms
10,880 KB |
testcase_18 | AC | 31 ms
10,880 KB |
testcase_19 | AC | 31 ms
10,752 KB |
testcase_20 | AC | 31 ms
10,880 KB |
testcase_21 | AC | 30 ms
10,752 KB |
testcase_22 | AC | 30 ms
10,752 KB |
testcase_23 | AC | 31 ms
10,752 KB |
testcase_24 | AC | 31 ms
10,624 KB |
testcase_25 | AC | 32 ms
10,880 KB |
testcase_26 | AC | 31 ms
10,752 KB |
testcase_27 | AC | 31 ms
10,752 KB |
testcase_28 | AC | 30 ms
10,752 KB |
testcase_29 | AC | 30 ms
10,752 KB |
testcase_30 | AC | 30 ms
10,880 KB |
testcase_31 | AC | 31 ms
10,752 KB |
testcase_32 | AC | 31 ms
10,880 KB |
testcase_33 | AC | 31 ms
10,752 KB |
testcase_34 | AC | 31 ms
10,752 KB |
testcase_35 | AC | 31 ms
10,880 KB |
testcase_36 | AC | 31 ms
10,752 KB |
testcase_37 | AC | 31 ms
10,752 KB |
testcase_38 | AC | 31 ms
10,880 KB |
testcase_39 | AC | 32 ms
10,752 KB |
testcase_40 | AC | 31 ms
10,880 KB |
testcase_41 | AC | 32 ms
10,880 KB |
testcase_42 | AC | 30 ms
10,752 KB |
testcase_43 | AC | 37 ms
11,008 KB |
testcase_44 | AC | 34 ms
10,752 KB |
testcase_45 | AC | 33 ms
10,624 KB |
testcase_46 | AC | 35 ms
11,136 KB |
testcase_47 | AC | 33 ms
10,880 KB |
testcase_48 | AC | 35 ms
11,008 KB |
testcase_49 | AC | 31 ms
10,880 KB |
testcase_50 | AC | 37 ms
11,136 KB |
testcase_51 | AC | 36 ms
11,008 KB |
testcase_52 | AC | 37 ms
11,136 KB |
testcase_53 | AC | 36 ms
11,008 KB |
testcase_54 | AC | 37 ms
11,136 KB |
testcase_55 | AC | 36 ms
11,008 KB |
testcase_56 | AC | 32 ms
10,880 KB |
testcase_57 | AC | 35 ms
11,008 KB |
testcase_58 | AC | 35 ms
10,880 KB |
testcase_59 | AC | 31 ms
10,880 KB |
testcase_60 | AC | 32 ms
10,880 KB |
testcase_61 | AC | 36 ms
11,008 KB |
testcase_62 | AC | 32 ms
10,752 KB |
testcase_63 | AC | 94 ms
14,720 KB |
testcase_64 | AC | 47 ms
11,648 KB |
testcase_65 | AC | 72 ms
13,440 KB |
testcase_66 | AC | 61 ms
12,544 KB |
testcase_67 | AC | 43 ms
11,392 KB |
testcase_68 | AC | 67 ms
13,184 KB |
testcase_69 | AC | 77 ms
13,824 KB |
testcase_70 | AC | 50 ms
12,160 KB |
testcase_71 | AC | 46 ms
11,648 KB |
testcase_72 | AC | 80 ms
13,816 KB |
testcase_73 | AC | 49 ms
12,032 KB |
testcase_74 | AC | 74 ms
13,440 KB |
testcase_75 | AC | 64 ms
12,800 KB |
testcase_76 | AC | 38 ms
11,264 KB |
testcase_77 | AC | 59 ms
12,544 KB |
testcase_78 | AC | 86 ms
14,208 KB |
testcase_79 | AC | 90 ms
14,464 KB |
testcase_80 | AC | 82 ms
14,080 KB |
testcase_81 | AC | 89 ms
14,336 KB |
testcase_82 | AC | 85 ms
14,336 KB |
testcase_83 | AC | 866 ms
52,000 KB |
testcase_84 | AC | 832 ms
50,920 KB |
testcase_85 | AC | 489 ms
35,172 KB |
testcase_86 | AC | 675 ms
43,720 KB |
testcase_87 | AC | 738 ms
46,396 KB |
testcase_88 | AC | 123 ms
16,540 KB |
testcase_89 | AC | 835 ms
51,696 KB |
testcase_90 | AC | 515 ms
36,424 KB |
testcase_91 | AC | 395 ms
31,648 KB |
testcase_92 | AC | 211 ms
21,656 KB |
testcase_93 | AC | 635 ms
42,148 KB |
testcase_94 | AC | 577 ms
39,328 KB |
testcase_95 | AC | 578 ms
39,340 KB |
testcase_96 | AC | 764 ms
49,904 KB |
testcase_97 | AC | 336 ms
27,632 KB |
testcase_98 | AC | 774 ms
50,120 KB |
testcase_99 | AC | 449 ms
34,368 KB |
testcase_100 | AC | 864 ms
52,600 KB |
testcase_101 | AC | 188 ms
20,768 KB |
testcase_102 | AC | 111 ms
16,004 KB |
testcase_103 | AC | 206 ms
21,680 KB |
testcase_104 | AC | 285 ms
25,376 KB |
testcase_105 | AC | 642 ms
42,140 KB |
testcase_106 | AC | 369 ms
30,424 KB |
testcase_107 | AC | 826 ms
51,592 KB |
testcase_108 | AC | 845 ms
51,300 KB |
testcase_109 | AC | 639 ms
41,844 KB |
testcase_110 | AC | 567 ms
39,252 KB |
testcase_111 | AC | 615 ms
40,968 KB |
testcase_112 | AC | 270 ms
24,452 KB |
testcase_113 | AC | 579 ms
38,416 KB |
testcase_114 | AC | 352 ms
28,628 KB |
testcase_115 | AC | 135 ms
17,112 KB |
testcase_116 | AC | 420 ms
32,512 KB |
testcase_117 | AC | 272 ms
24,684 KB |
testcase_118 | AC | 758 ms
49,800 KB |
testcase_119 | AC | 459 ms
34,240 KB |
testcase_120 | AC | 732 ms
46,064 KB |
testcase_121 | AC | 226 ms
22,820 KB |
testcase_122 | AC | 404 ms
31,976 KB |
testcase_123 | AC | 31 ms
10,752 KB |
testcase_124 | RE | - |
testcase_125 | RE | - |
ソースコード
# Python program to find bridges in a given undirected graph #Complexity : O(V+E) from collections import defaultdict #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))