8000 Merge pull request #479 from haneulkimdev/master-2 · hackerman91/basic-algo-lecture@e530e83 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e530e83

Browse files
Merge pull request encrypted-def#479 from haneulkimdev/master-2
Create 16398_1.cpp
2 parents aad4dce + 53edcb8 commit e530e83

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

0x1B/solutions/16398_1.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Authored by : haneulkimdev
2+
// Co-authored by : -
3+
// http://boj.kr/4bf034b6c2d945d29716a5483d78bb28
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[1001];
11+
bool chk[1001];
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+
for (int j = 1; j <= n; j++) {
19+
int c;
20+
cin >> c;
21+
if (i >= j) continue;
22+
adj[i].push_back({c, j});
23+
adj[j].push_back({c, i});
24+
}
25+
}
26+
int cnt = 0;
27+
long long ans = 0;
28+
priority_queue<pair<int, int>, vector<pair<int, int>>,
29+
greater<pair<int, int>>>
30+
pq;
31+
chk[1] = true;
32+
for (auto nxt : adj[1]) pq.push(nxt);
33+
while (cnt < n - 1) {
34+
auto cur = pq.top();
35+
pq.pop();
36+
if (chk[cur.Y]) continue;
37+
ans += cur.X;
38+
chk[cur.Y] = true;
39+
cnt++;
40+
for (auto nxt : adj[cur.Y])
41+
if (!chk[nxt.Y]) pq.push(nxt);
42+
}
43+
cout << ans;
44+
}

0 commit comments

Comments
 (0)
0