-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path107 - Minimal network.cpp
58 lines (51 loc) · 1.09 KB
/
107 - Minimal network.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
const int N=40;
int dis[N+5][N+5];
bool vis[N+5];
struct node {
int id,val;
bool operator<(const node& rhs) const {
return val>rhs.val;
}
};
int main() {
int sum=0;
freopen("input.txt","r",stdin);
for (int i=1;i<=N;i++) {
for (int j=1;j<=N;j++) {
scanf("%d",&dis[i][j]);
if (j>i) sum+=dis[i][j];
}
}
priority_queue<node> pq;
pq.push({1,0});
int cnt=0;
int ans=0;
while (cnt<N) {
node cur=pq.top();
pq.pop();
if (vis[cur.id]) continue;
vis[cur.id]=1;
cnt++;
ans+=cur.val;
for (int i=1;i<=N;i++) {
if (!vis[i]&&dis[cur.id][i]>0) {
pq.push({i,dis[cur.id][i]});
}
}
}
printf("sum:%d ans:%d\n",sum,sum-ans);
}