結果

問題 No.1254 補強への架け橋
ユーザー yuusanlondonyuusanlondon
提出日時 2020-10-09 22:51:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 705 ms / 2,000 ms
コード長 3,052 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 210,744 KB
最終ジャッジ日時 2023-09-27 18:53:47
合計ジャッジ時間 29,441 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,272 KB
testcase_01 AC 85 ms
71,496 KB
testcase_02 AC 83 ms
71,540 KB
testcase_03 AC 85 ms
71,460 KB
testcase_04 AC 83 ms
71,576 KB
testcase_05 AC 86 ms
71,520 KB
testcase_06 AC 84 ms
71,544 KB
testcase_07 AC 83 ms
71,540 KB
testcase_08 AC 82 ms
71,664 KB
testcase_09 AC 85 ms
71,612 KB
testcase_10 AC 85 ms
71,292 KB
testcase_11 AC 84 ms
71,792 KB
testcase_12 AC 85 ms
71,412 KB
testcase_13 AC 87 ms
71,416 KB
testcase_14 AC 85 ms
71,404 KB
testcase_15 AC 85 ms
71,620 KB
testcase_16 AC 80 ms
71,656 KB
testcase_17 AC 82 ms
71,516 KB
testcase_18 AC 83 ms
71,488 KB
testcase_19 AC 83 ms
71,500 KB
testcase_20 AC 86 ms
71,788 KB
testcase_21 AC 83 ms
71,488 KB
testcase_22 AC 85 ms
71,532 KB
testcase_23 AC 84 ms
71,460 KB
testcase_24 AC 88 ms
71,664 KB
testcase_25 AC 86 ms
71,780 KB
testcase_26 AC 84 ms
71,412 KB
testcase_27 AC 84 ms
71,500 KB
testcase_28 AC 86 ms
71,664 KB
testcase_29 AC 84 ms
71,456 KB
testcase_30 AC 85 ms
71,296 KB
testcase_31 AC 83 ms
71,488 KB
testcase_32 AC 81 ms
71,476 KB
testcase_33 AC 86 ms
71,792 KB
testcase_34 AC 83 ms
71,296 KB
testcase_35 AC 85 ms
71,456 KB
testcase_36 AC 83 ms
71,500 KB
testcase_37 AC 84 ms
71,420 KB
testcase_38 AC 86 ms
71,456 KB
testcase_39 AC 87 ms
71,516 KB
testcase_40 AC 86 ms
71,456 KB
testcase_41 AC 84 ms
71,496 KB
testcase_42 AC 85 ms
71,512 KB
testcase_43 AC 100 ms
76,696 KB
testcase_44 AC 88 ms
72,200 KB
testcase_45 AC 90 ms
72,232 KB
testcase_46 AC 103 ms
76,700 KB
testcase_47 AC 94 ms
72,116 KB
testcase_48 AC 104 ms
77,252 KB
testcase_49 AC 88 ms
71,664 KB
testcase_50 AC 108 ms
77,056 KB
testcase_51 AC 110 ms
77,236 KB
testcase_52 AC 111 ms
77,300 KB
testcase_53 AC 110 ms
76,724 KB
testcase_54 AC 110 ms
77,312 KB
testcase_55 AC 101 ms
76,056 KB
testcase_56 AC 92 ms
72,048 KB
testcase_57 AC 94 ms
76,044 KB
testcase_58 AC 96 ms
75,788 KB
testcase_59 AC 85 ms
71,452 KB
testcase_60 AC 89 ms
72,076 KB
testcase_61 AC 99 ms
76,168 KB
testcase_62 AC 87 ms
72,312 KB
testcase_63 AC 167 ms
80,628 KB
testcase_64 AC 144 ms
80,348 KB
testcase_65 AC 154 ms
79,928 KB
testcase_66 AC 164 ms
80,468 KB
testcase_67 AC 129 ms
79,572 KB
testcase_68 AC 152 ms
79,788 KB
testcase_69 AC 158 ms
80,340 KB
testcase_70 AC 140 ms
79,968 KB
testcase_71 AC 136 ms
79,560 KB
testcase_72 AC 150 ms
79,960 KB
testcase_73 AC 151 ms
80,060 KB
testcase_74 AC 152 ms
80,088 KB
testcase_75 AC 165 ms
80,232 KB
testcase_76 AC 120 ms
77,952 KB
testcase_77 AC 152 ms
80,156 KB
testcase_78 AC 174 ms
82,212 KB
testcase_79 AC 159 ms
79,972 KB
testcase_80 AC 157 ms
80,764 KB
testcase_81 AC 160 ms
80,476 KB
testcase_82 AC 155 ms
79,828 KB
testcase_83 AC 366 ms
105,444 KB
testcase_84 AC 354 ms
103,480 KB
testcase_85 AC 265 ms
95,116 KB
testcase_86 AC 318 ms
99,256 KB
testcase_87 AC 347 ms
102,316 KB
testcase_88 AC 170 ms
82,736 KB
testcase_89 AC 366 ms
105,232 KB
testcase_90 AC 271 ms
96,052 KB
testcase_91 AC 251 ms
92,164 KB
testcase_92 AC 189 ms
86,464 KB
testcase_93 AC 308 ms
100,312 KB
testcase_94 AC 291 ms
98,300 KB
testcase_95 AC 296 ms
98,332 KB
testcase_96 AC 359 ms
103,012 KB
testcase_97 AC 231 ms
89,668 KB
testcase_98 AC 369 ms
103,352 KB
testcase_99 AC 270 ms
93,480 KB
testcase_100 AC 396 ms
105,884 KB
testcase_101 AC 201 ms
85,724 KB
testcase_102 AC 170 ms
81,756 KB
testcase_103 AC 200 ms
86,344 KB
testcase_104 AC 231 ms
88,796 KB
testcase_105 AC 332 ms
99,888 KB
testcase_106 AC 237 ms
90,448 KB
testcase_107 AC 389 ms
104,860 KB
testcase_108 AC 377 ms
105,208 KB
testcase_109 AC 319 ms
99,464 KB
testcase_110 AC 311 ms
98,616 KB
testcase_111 AC 308 ms
97,500 KB
testcase_112 AC 224 ms
89,016 KB
testcase_113 AC 304 ms
97,748 KB
testcase_114 AC 236 ms
89,268 KB
testcase_115 AC 180 ms
83,316 KB
testcase_116 AC 250 ms
92,524 KB
testcase_117 AC 212 ms
88,656 KB
testcase_118 AC 355 ms
103,080 KB
testcase_119 AC 261 ms
93,308 KB
testcase_120 AC 339 ms
102,192 KB
testcase_121 AC 199 ms
87,292 KB
testcase_122 AC 242 ms
92,112 KB
testcase_123 AC 84 ms
71,616 KB
testcase_124 AC 705 ms
208,896 KB
testcase_125 AC 701 ms
210,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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))
0