結果

問題 No.1254 補強への架け橋
ユーザー yuusanlondonyuusanlondon
提出日時 2020-10-09 22:44:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 3,020 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 105,336 KB
最終ジャッジ日時 2024-07-20 13:10:16
合計ジャッジ時間 22,930 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,888 KB
testcase_01 AC 39 ms
53,632 KB
testcase_02 AC 43 ms
53,760 KB
testcase_03 AC 40 ms
53,632 KB
testcase_04 AC 41 ms
54,016 KB
testcase_05 AC 40 ms
54,272 KB
testcase_06 AC 39 ms
53,888 KB
testcase_07 AC 40 ms
54,144 KB
testcase_08 AC 40 ms
53,760 KB
testcase_09 AC 40 ms
53,888 KB
testcase_10 AC 40 ms
53,504 KB
testcase_11 AC 39 ms
53,504 KB
testcase_12 AC 40 ms
53,888 KB
testcase_13 AC 41 ms
53,888 KB
testcase_14 AC 40 ms
54,144 KB
testcase_15 AC 40 ms
53,632 KB
testcase_16 AC 40 ms
53,760 KB
testcase_17 AC 40 ms
53,632 KB
testcase_18 AC 39 ms
53,888 KB
testcase_19 AC 38 ms
54,016 KB
testcase_20 AC 41 ms
54,272 KB
testcase_21 AC 39 ms
54,272 KB
testcase_22 AC 40 ms
53,888 KB
testcase_23 AC 41 ms
53,632 KB
testcase_24 AC 41 ms
54,144 KB
testcase_25 AC 39 ms
54,016 KB
testcase_26 AC 41 ms
54,272 KB
testcase_27 AC 40 ms
53,888 KB
testcase_28 AC 41 ms
54,016 KB
testcase_29 AC 40 ms
53,888 KB
testcase_30 AC 40 ms
53,888 KB
testcase_31 AC 42 ms
54,400 KB
testcase_32 AC 40 ms
53,632 KB
testcase_33 AC 41 ms
54,528 KB
testcase_34 AC 41 ms
54,144 KB
testcase_35 AC 40 ms
53,888 KB
testcase_36 AC 46 ms
54,016 KB
testcase_37 AC 46 ms
54,016 KB
testcase_38 AC 47 ms
54,656 KB
testcase_39 AC 41 ms
54,528 KB
testcase_40 AC 43 ms
54,144 KB
testcase_41 AC 42 ms
53,760 KB
testcase_42 AC 42 ms
53,760 KB
testcase_43 AC 59 ms
64,896 KB
testcase_44 AC 46 ms
55,808 KB
testcase_45 AC 52 ms
55,680 KB
testcase_46 AC 59 ms
64,896 KB
testcase_47 AC 48 ms
56,704 KB
testcase_48 AC 64 ms
67,072 KB
testcase_49 AC 43 ms
54,400 KB
testcase_50 AC 65 ms
66,944 KB
testcase_51 AC 64 ms
67,328 KB
testcase_52 AC 74 ms
69,632 KB
testcase_53 AC 60 ms
65,280 KB
testcase_54 AC 68 ms
68,736 KB
testcase_55 AC 59 ms
64,000 KB
testcase_56 AC 46 ms
54,656 KB
testcase_57 AC 59 ms
62,592 KB
testcase_58 AC 55 ms
62,336 KB
testcase_59 AC 42 ms
54,528 KB
testcase_60 AC 47 ms
55,424 KB
testcase_61 AC 61 ms
64,000 KB
testcase_62 AC 43 ms
54,528 KB
testcase_63 AC 121 ms
80,000 KB
testcase_64 AC 104 ms
77,696 KB
testcase_65 AC 115 ms
78,208 KB
testcase_66 AC 123 ms
78,720 KB
testcase_67 AC 96 ms
77,440 KB
testcase_68 AC 112 ms
77,524 KB
testcase_69 AC 121 ms
78,848 KB
testcase_70 AC 129 ms
78,080 KB
testcase_71 AC 117 ms
77,824 KB
testcase_72 AC 113 ms
77,696 KB
testcase_73 AC 103 ms
77,568 KB
testcase_74 AC 114 ms
77,952 KB
testcase_75 AC 116 ms
78,208 KB
testcase_76 AC 79 ms
74,240 KB
testcase_77 AC 113 ms
78,080 KB
testcase_78 AC 129 ms
79,616 KB
testcase_79 AC 120 ms
79,104 KB
testcase_80 AC 122 ms
79,232 KB
testcase_81 AC 121 ms
79,488 KB
testcase_82 AC 118 ms
78,976 KB
testcase_83 AC 307 ms
103,312 KB
testcase_84 AC 296 ms
101,048 KB
testcase_85 AC 214 ms
94,168 KB
testcase_86 AC 272 ms
98,096 KB
testcase_87 AC 292 ms
101,428 KB
testcase_88 AC 134 ms
81,408 KB
testcase_89 AC 312 ms
103,556 KB
testcase_90 AC 227 ms
93,044 KB
testcase_91 AC 216 ms
90,644 KB
testcase_92 AC 160 ms
85,632 KB
testcase_93 AC 268 ms
97,432 KB
testcase_94 AC 268 ms
95,644 KB
testcase_95 AC 248 ms
95,900 KB
testcase_96 AC 306 ms
101,360 KB
testcase_97 AC 189 ms
87,900 KB
testcase_98 AC 340 ms
101,016 KB
testcase_99 AC 245 ms
92,640 KB
testcase_100 AC 362 ms
102,480 KB
testcase_101 AC 164 ms
84,992 KB
testcase_102 AC 134 ms
80,768 KB
testcase_103 AC 168 ms
86,528 KB
testcase_104 AC 203 ms
85,788 KB
testcase_105 AC 275 ms
97,436 KB
testcase_106 AC 220 ms
88,988 KB
testcase_107 AC 334 ms
102,528 KB
testcase_108 AC 317 ms
102,360 KB
testcase_109 AC 281 ms
97,016 KB
testcase_110 AC 266 ms
96,348 KB
testcase_111 AC 253 ms
95,280 KB
testcase_112 AC 184 ms
85,804 KB
testcase_113 AC 291 ms
95,644 KB
testcase_114 AC 217 ms
88,660 KB
testcase_115 AC 147 ms
82,176 KB
testcase_116 AC 216 ms
90,984 KB
testcase_117 AC 174 ms
85,308 KB
testcase_118 AC 316 ms
101,076 KB
testcase_119 AC 216 ms
92,496 KB
testcase_120 AC 311 ms
100,572 KB
testcase_121 AC 159 ms
86,016 KB
testcase_122 AC 203 ms
91,168 KB
testcase_123 AC 40 ms
53,888 KB
testcase_124 RE -
testcase_125 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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