8000 Merge pull request #478 from haneulkimdev/master-1 · dkim-coder/basic-algo-lecture@aad4dce · GitHub
[go: up one dir, main page]

Skip to content

Commit aad4dce

Browse files
Merge pull request encrypted-def#478 from haneulkimdev/master-1
Create 1368_1.cpp
2 parents 8d6d545 + 324e239 commit aad4dce

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

0x1B/solutions/1368_1.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Authored by : haneulkimdev
2+
// Co-authored by : -
3+
// http://boj.kr/aca5c2d5eed04bc1aac87a0d4bd1d674
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
#define X first
7+
#define Y second
8+
9+
int n;
10+
vector<pair<int, int>> adj[100001];
11+
bool chk[100001];
12+
13+
int main(void) {
14+
ios::sync_with_stdio(0);
15+
cin.tie(0);
16+
cin >> n;
17+
for (int i = 1; i <= n; i++) {
18+
int w;
19+
cin >> w;
20+
adj[i].push_back({w, 0});
21+
adj[0].push_back({w, i});
22+
}
23+
for (int i 8000 = 1; i <= n; i++) {
24+
for (int j = 1; j <= n; j++) {
25+
int p;
26+
cin >> p;
27+
if (i >= j) continue;
28+
adj[i].push_back({p, j});
29+
adj[j].push_back({p, i});
30+
}
31+
}
32+
int cnt = 0;
33+
int ans = 0;
34+
priority_queue<pair<int, int>, vector<pair<int, int>>,
35+
greater<pair<int, int>>>
36+
pq;
37+
chk[0] = true;
38+
for (auto nxt : adj[0]) pq.push(nxt);
39+
while (cnt < n) {
40+
auto cur = pq.top();
41+
pq.pop();
42+
if (chk[cur.Y]) continue;
43+
ans += cur.X;
44+
chk[cur.Y] = true;
45+
cnt++;
46+
for (auto nxt : adj[cur.Y])
47+
if (!chk[nxt.Y]) pq.push(nxt);
48+
}
49+
cout << ans;
50+
}

0 commit comments

Comments
 (0)
0