From 4a44005f35aeda02e6247158a907e813067c2758 Mon Sep 17 00:00:00 2001 From: LeeSongMi <33647862+LeeSongMi@users.noreply.github.com> Date: Mon, 19 May 2025 00:07:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B3=84=EC=9E=90=EB=A6=AC=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pine/code.py" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "04_\353\263\204\354\236\220\353\246\254\353\247\214\353\223\244\352\270\260/pine/code.py" diff --git "a/04_\353\263\204\354\236\220\353\246\254\353\247\214\353\223\244\352\270\260/pine/code.py" "b/04_\353\263\204\354\236\220\353\246\254\353\247\214\353\223\244\352\270\260/pine/code.py" new file mode 100644 index 0000000..cf3564e --- /dev/null +++ "b/04_\353\263\204\354\236\220\353\246\254\353\247\214\353\223\244\352\270\260/pine/code.py" @@ -0,0 +1,40 @@ +import math + +n = int(input()) + +stars = [list(map(float,input().split())) for _ in range(n)] # 별들의 좌표 정보 +root = [i for i in range(n)] # 별의 root 정보가 담긴 배열 +cost = 0 # 정답 비용 +edge = [] # 모든 별들이 연결된 간선 정보와 별 사이의 거리를 저장할 배열. 구조:모든 간선 정보[거리, 시작인덱스, 종료 인덱스] + +def getDistance(star1,star2): + x1, y1=star1 + x2, y2=star2 + return math.sqrt((x2-x1)**2 + (y2-y1)**2) + +def find(x): + if root[x]!=x: + root[x]=find(root[x]) + return root[x] + +def union(star1,star2): + root1=find(star1) + root2=find(star2) + + if root1 root별이 같은데 union하면 사이클이 발생하기 때문 + if find(index1) != find(index2): # root별이 같지 않을 경우(= 사이클이 발생하지 않는 경우, => 이상태에서 unioin을 하면 그때 사이클이 발생한다.) + union(index1,index2) # index1,index2의 별을 연결 + cost+=distance + +print(f"{cost:.2f}") \ No newline at end of file