# 1197 최소 스패닝 트리

문제 : <https://www.acmicpc.net/problem/1197>

```python
import sys
input = sys.stdin.readline

V, E = map(int, input().split())

Edges = []

for _ in range(E):
    A, B, C = map(int, input().split())
    Edges.append([A, B, C])

def third_val(e):
    return(e[2])

Edges.sort(key = third_val)

# 각 정점이 들어있는 유니온을 기록함
union = [i for i in range(V)]

def kruskal(edge):
    s = union[edge[0]-1]
    e = union[edge[1]-1]

    if s == e:
        return 0
    else:
        for i in range(V):
            if union[i] == s:
                union[i] = e
        return edge[2]

result = 0
for edge in Edges:
    result += kruskal(edge)
print(result)
```

각 정점이 속해있는 유니온을 숫자로 추상화해서 풀었다.

리스트를 딕셔너리로 바꾼다던가 하면 더 빨라질듯?\
지금은 유니온을 정점 개수만큼 선언한 뒤에 매번 훑어서 좀 느리다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lazyartisan.gitbook.io/note/main-page/algorithm/undefined-1/1197.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
