From aeab8971d1f06795ba56624e7364fae6e7802491 Mon Sep 17 00:00:00 2001 From: YeEun <66158433+ise-yen@users.noreply.github.com> Date: Sat, 27 Apr 2024 23:32:23 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[BOJ]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B0=BE=EA=B8=B0=20/=20=EC=8B=A4=EB=B2=844=20/=20?= =?UTF-8?q?10=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\230\270 \354\260\276\352\270\260.cpp" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "ise-yen/BOJ/Hash/\353\271\204\353\260\200\353\262\210\355\230\270 \354\260\276\352\270\260.cpp" diff --git "a/ise-yen/BOJ/Hash/\353\271\204\353\260\200\353\262\210\355\230\270 \354\260\276\352\270\260.cpp" "b/ise-yen/BOJ/Hash/\353\271\204\353\260\200\353\262\210\355\230\270 \354\260\276\352\270\260.cpp" new file mode 100644 index 000000000..dbf58b058 --- /dev/null +++ "b/ise-yen/BOJ/Hash/\353\271\204\353\260\200\353\262\210\355\230\270 \354\260\276\352\270\260.cpp" @@ -0,0 +1,23 @@ +#include +#include + +using namespace std; + +int main() { + cin.tie(0); + ios::sync_with_stdio(0); + int N{}, M{}; + cin >> N >> M; + unordered_map um; + for (int i = 0; i < N; i++) { + string site{}, pswr{}; + cin >> site >> pswr; + um.insert({ site, pswr }); + } + for (int i = 0; i < M; i++) { + string site{}; + cin >> site; + cout << um[site] << "\n"; + } + return 0; +} From d44312b8fd746363dea5debb68a4f39e06526b7f Mon Sep 17 00:00:00 2001 From: YeEun <66158433+ise-yen@users.noreply.github.com> Date: Wed, 1 May 2024 23:05:03 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[BOJ]=20=EC=B5=9C=EC=86=8C=20=EC=8A=A4?= =?UTF-8?q?=ED=8C=A8=EB=8B=9D=20=ED=8A=B8=EB=A6=AC=20/=20=EA=B3=A8?= =?UTF-8?q?=EB=93=9C4=20/=2040=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\213\235 \355\212\270\353\246\254.cpp" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "ise-yen/BOJ/Kruskal/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.cpp" diff --git "a/ise-yen/BOJ/Kruskal/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.cpp" "b/ise-yen/BOJ/Kruskal/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.cpp" new file mode 100644 index 000000000..4b7d3157e --- /dev/null +++ "b/ise-yen/BOJ/Kruskal/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.cpp" @@ -0,0 +1,69 @@ +#include +#include +#include + +using namespace std; + +const int MAX = 100001; +int N{}, M{}; +int memo[MAX]; + +vector < pair>> edges; +int result; + +// 집합 찾기 +int Find(int v) { + if (v == memo[v]) return v; + else return memo[v] = Find(memo[v]); +} + +// 집합 만들기 +void UnionV(int a, int b, int c) { + a = Find(a); + b = Find(b); + if (a != b) result += c; + if (a < b) memo[b] = a; + else memo[a] = b; +} + +// 초기화 +void Initial() { + // 메모이제이션용 메모를 자기 자신으로 초기화 + for (int i = 1; i <= N; i++) { + memo[i] = i; + } +} + +// 간선 정보 입력 +void Input() { + for (int i = 0; i < M; i++) { + int a{}, b{}, c{}; + cin >> a >> b >> c; + edges.push_back({ c, {a, b} }); + } +} + +// 크루스칼 알고리즘 +void Kruskal() { + // 정렬 + sort(edges.begin(), edges.end()); + + for (int i = 0; i < edges.size(); i++) { + int c = edges[i].first; + int a = edges[i].second.first; + int b = edges[i].second.second; + // 집합화 + UnionV(a, b, c); + } +} + +int main() { + cin.tie(); + ios::sync_with_stdio(false); + cin >> N >> M; + Initial(); + Input(); + Kruskal(); + cout << result; + return 0; +} From 8ec648a18b21aea5b462661868627f4c17e7c3a6 Mon Sep 17 00:00:00 2001 From: YeEun <66158433+ise-yen@users.noreply.github.com> Date: Fri, 3 May 2024 00:04:18 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[BOJ]=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=20=EC=97=B0=EA=B2=B0=20/=20=EA=B3=A8=EB=93=9C4=20/=20?= =?UTF-8?q?10=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\355\201\254 \354\227\260\352\262\260.cpp" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "ise-yen/BOJ/Kruskal/\353\204\244\355\212\270\354\233\214\355\201\254 \354\227\260\352\262\260.cpp" diff --git "a/ise-yen/BOJ/Kruskal/\353\204\244\355\212\270\354\233\214\355\201\254 \354\227\260\352\262\260.cpp" "b/ise-yen/BOJ/Kruskal/\353\204\244\355\212\270\354\233\214\355\201\254 \354\227\260\352\262\260.cpp" new file mode 100644 index 000000000..2c12414fa --- /dev/null +++ "b/ise-yen/BOJ/Kruskal/\353\204\244\355\212\270\354\233\214\355\201\254 \354\227\260\352\262\260.cpp" @@ -0,0 +1,53 @@ +#include +#include +#include + +using namespace std; + +int result{}, N{}, M{}; +int memo[100001]; + +int Find(int n) { + if (memo[n] == n) return n; + else return memo[n] = Find(memo[n]); +} + +void Union(int a, int b, int c) { + a = Find(a); + b = Find(b); + if (a != b) result += c; + if (a < b) memo[b] = a; + else memo[a] = b; +} + +int main() { + cin.tie(); + ios::sync_with_stdio(false); + + cin >> N >> M; + vector>> v; // c, a , b; + + // 초기화 + for (int i = 1; i <= N; i++) { + memo[i] = i; + } + + // 입력 + for (int i = 0; i < M; i++) { + int a{}, b{}, c{}; + cin >> a >> b >> c; + v.push_back({ c, {a, b} }); + } + + sort(v.begin(), v.end()); + + for (int i = 0; i < v.size(); i++) { + int c = v[i].first; + int a = v[i].second.first; + int b = v[i].second.second; + Union(a, b, c); + } + + cout << result; + return 0; +} From 4fc1d907839221c50b0d8a806f65dd290c5b971e Mon Sep 17 00:00:00 2001 From: YeEun <66158433+ise-yen@users.noreply.github.com> Date: Sun, 5 May 2024 17:52:02 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[BOJ]=20=ED=96=89=EC=84=B1=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20/=20=EA=B3=A8=EB=93=9C4=20/=201=EC=8B=9C=EA=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 자료형 범위 주의 --- ...\354\204\261 \354\227\260\352\262\260.cpp" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "ise-yen/BOJ/Kruskal/\355\226\211\354\204\261 \354\227\260\352\262\260.cpp" diff --git "a/ise-yen/BOJ/Kruskal/\355\226\211\354\204\261 \354\227\260\352\262\260.cpp" "b/ise-yen/BOJ/Kruskal/\355\226\211\354\204\261 \354\227\260\352\262\260.cpp" new file mode 100644 index 000000000..54f1ed9ba --- /dev/null +++ "b/ise-yen/BOJ/Kruskal/\355\226\211\354\204\261 \354\227\260\352\262\260.cpp" @@ -0,0 +1,59 @@ +#include +#include +#include + +using namespace std; + +const int MAX = 1001; +int memo[MAX]; +unsigned long long result{}; + +int Find(int n) { + if (memo[n] == n) return n; + else return memo[n] = Find(memo[n]); +} + +void Union(int a, int b, int c) { + a = Find(a); + b = Find(b); + if (a != b) result += c; + if (a < b) memo[b] = a; + else memo[a] = b; +} + +int main() { + cin.tie(); + ios::sync_with_stdio(false); + + int N{}; + cin >> N; + for (int i = 1; i <= N; i++) { + memo[i] = i; + } + vector tmp(N + 1); + vector> map(N + 1, tmp); + + vector>> v; + + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + cin >> map[i][j]; + if (j > i) { + v.push_back({map[i][j], {i, j}}); + } + } + } + + sort(v.begin(), v.end()); + + for (int i = 0; i < v.size(); i++) { + int c = v[i].first; + int a = v[i].second.first; + int b = v[i].second.second; + Union(a, b, c); + } + + cout << result; + + return 0; +} From 22b71500944c190dc31e401fb832ddd48d844c16 Mon Sep 17 00:00:00 2001 From: YeEun <66158433+ise-yen@users.noreply.github.com> Date: Wed, 8 May 2024 00:47:58 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[BOJ]=20=EB=8F=84=EC=8B=9C=20=EA=B1=B4?= =?UTF-8?q?=EC=84=A4=20/=20=EA=B3=A8=EB=93=9C4=20/=2030=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\354\213\234 \352\261\264\354\204\244.cpp" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "ise-yen/BOJ/Kruskal/\353\217\204\354\213\234 \352\261\264\354\204\244.cpp" diff --git "a/ise-yen/BOJ/Kruskal/\353\217\204\354\213\234 \352\261\264\354\204\244.cpp" "b/ise-yen/BOJ/Kruskal/\353\217\204\354\213\234 \352\261\264\354\204\244.cpp" new file mode 100644 index 000000000..88f9193b3 --- /dev/null +++ "b/ise-yen/BOJ/Kruskal/\353\217\204\354\213\234 \352\261\264\354\204\244.cpp" @@ -0,0 +1,67 @@ +#include +#include +#include + +using namespace std; + +const int MAX = 100001; +int N{}, M{}; +long long cost{}; +int memo[MAX]{}; + +int Find(int n) { + if (n == memo[n]) return n; + else return memo[n] = Find(memo[n]); +} + +void Union(int a, int b, int c) { + a = Find(a); + b = Find(b); + + if (a != b) cost += c; + if (a < b) memo[b] = a; + else memo[a] = b; +} + + + +int main() { + cin.tie(0); + ios::sync_with_stdio(false); + + cin >> N >> M; + for (int i = 1; i <= N; i++) { + memo[i] = i; + } + + long long sum{}; + vector>> v; + + for (int i = 0; i < M; i++) { + int a{}, b{}, c{}; + cin >> a >> b >> c; + sum += c; + v.push_back({ c, {a, b} }); + } + + sort(v.begin(), v.end()); + + for (int i = 0; i < v.size(); i++) { + int c = v[i].first; + int a = v[i].second.first; + int b = v[i].second.second; + Union(a, b, c); + } + + bool isSame = true; + for (int i = 1; i < N; i++) { + if (Find(i) != Find(i + 1)) { + isSame = false; + break; + } + } + if (isSame) cout << sum - cost; + else cout << -1; + + return 0; +}