Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17-seongwon030 #67

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

input = sys.stdin.readline

V,E = map(int,input().split())
root = [i for i in range(V+1)]
edge = [] # ๊ฐ„์„ ๋ฆฌ์ŠคํŠธ
for i in range(E):
edge.append(list(map(int,input().split())))

# ๋น„์šฉ์„ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ
edge.sort(key=lambda x:x[2])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ๋Š” x[2] ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค๋Š” ์˜๋ฏธ์ธ๊ฐ€์š”?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ตํ•ด์ค˜

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ—‰ ์™œ ๋‹ต์„ ์•ˆํ–ˆ์ง€! ๋„ค ๋งž์Šต๋‹ˆ๋‹น

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ˆ๋กœ

 (lambda x,y: x + y)(10, 20)

๋Š” 10๊ณผ 20์„ ๋”ํ•œ ๊ฐ’์ธ 30์ด ๋‚˜์˜ค๋Š”๋ฐ

lambda ๋งค๊ฐœ๋ณ€์ˆ˜ : ํ‘œํ˜„์‹ 

์œผ๋กœ ํŒŒ์ด์ฌ์—์„œ๋Š” ํ‘œํ˜„ํ•ด์š”.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋žŒ๋‹คํ•จ์ˆ˜๋Š” ๋ด๋„๋ด๋„ ํ—ท๊ฐˆ๋ฆฌ๋„ค์š”..


def find(x):
if x!=root[x]:
root[x] = find(root[x])
return root[x]

ans = 0
for a,b,c in edge:
aRoot = find(a)
bRoot = find(b)
if aRoot != bRoot:
if aRoot > bRoot:
root[aRoot] = bRoot
else:
root[bRoot] = aRoot
ans += c

print(ans)