diff --git a/dohyeondol1/README.md b/dohyeondol1/README.md index 72a972d..f44924f 100644 --- a/dohyeondol1/README.md +++ b/dohyeondol1/README.md @@ -19,4 +19,5 @@ | 15차시 | 2025.05.22 | DFS | [석유 시추](https://school.programmers.co.kr/learn/courses/30/lessons/250136)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/60| | 16차시 | 2025.05.24 | BFS | [토마토](https://www.acmicpc.net/problem/7576)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/61| | 17차시 | 2025.06.26 | 기하학 | [선분 교차 2](https://www.acmicpc.net/problem/17387)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/65| - | 18차시 | 2025.07.04 | 기하학 | [Water Testing](https://www.acmicpc.net/problem/16057)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/70| \ No newline at end of file + | 18차시 | 2025.07.04 | 기하학 | [Water Testing](https://www.acmicpc.net/problem/16057)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/70| + | 19차시 | 2025.07.09 | 그래프 이론 | [최소 스패닝 트리](https://www.acmicpc.net/problem/1197)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/76| diff --git "a/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/19-dohyeondol1.cpp" "b/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/19-dohyeondol1.cpp" new file mode 100644 index 0000000..5509835 --- /dev/null +++ "b/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/19-dohyeondol1.cpp" @@ -0,0 +1,51 @@ +#include +#include +#include +#include +using namespace std; + +int prim(int V, const vector>>& adj) { + vector visited(V, false); + priority_queue, vector>, greater<>> pq; + + int totalWeight = 0; + pq.push({0, 0}); + + while(!pq.empty()) { + auto [weight, u] = pq.top(); + pq.pop(); + + if(visited[u]) continue; + visited[u] = true; + totalWeight += weight; + + for(auto& [w, v] : adj[u]) { + if(!visited[v]) { + pq.push({w, v}); + } + } + } + + return totalWeight; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int V, E; + cin >> V >> E; + vector>> adj(V); + + for(int i = 0; i < E; ++i) { + int A, B, C; + cin >> A >> B >> C; + + A--; B--; + adj[A].push_back({C, B}); + adj[B].push_back({C, A}); + } + + int mstWeight = prim(V, adj); + cout << mstWeight << '\n'; + return 0; +} \ No newline at end of file diff --git "a/dohyeondol1/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/3-dohyeondol1.cpp" "b/dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/3-dohyeondol1.cpp" similarity index 100% rename from "dohyeondol1/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/3-dohyeondol1.cpp" rename to "dohyeondol1/\352\267\270\353\236\230\355\224\204 \354\235\264\353\241\240/3-dohyeondol1.cpp"