Skip to content

Commit 84efec7

Browse files
committed
👑 G4-13905
1 parent fab53e6 commit 84efec7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

👑 G4/13905.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
input = sys.stdin.readline
3+
sys.setrecursionlimit(10**6)
4+
5+
n, m = map(int, input().split())
6+
s, e = map(int, input().split())
7+
8+
edges = []
9+
mst = []
10+
for _ in range(m):
11+
a, b, c = map(int, input().split())
12+
edges.append([c, a, b])
13+
edges.sort(reverse=True, key=lambda x:x[0])
14+
15+
parent = [i for i in range(n+1)]
16+
17+
def find(x):
18+
if x == parent[x]: return x
19+
parent[x] = find(parent[x])
20+
return parent[x]
21+
22+
def union(x, y):
23+
x = find(x)
24+
y = find(y)
25+
if x != y: parent[x] = y
26+
27+
for c, a, b in edges:
28+
if find(a) == find(b): continue
29+
mst.append(c)
30+
union(a, b)
31+
if find(s) == find(e):
32+
print(min(mst))
33+
break
34+
else:
35+
print(0)

0 commit comments

Comments
 (0)