#include<bits/stdc++.h>
using namespace std;
const int maxn=;
const int INF=0x3f3f3f3f;
inline void read(int &tmp)
{
int x=;char c=getchar();
for(tmp=;!isdigit(c);c=getchar()) if(c=='-') x=-;
for(;isdigit(c);tmp=tmp*+c-,c=getchar());
tmp*=x;
}
int n,sum,tot,m,mp[maxn][maxn],w[maxn];
typedef pair<int,int> P;
priority_queue< P,vector<P>,greater<P> >q;
bool v[maxn];
void Prim()
{
memset(w,0x3f,sizeof(w));
w[]=;q.push(make_pair(,));
while(!q.empty())
{
int Top=q.top().second;q.pop();
if(v[Top]) continue;
v[Top]=;sum+=w[Top];++tot;
for(int i=;i<=n;i++)
if(mp[Top][i]<w[i]&&mp[Top][i]>&&v[i]==false) {w[i]=mp[Top][i];q.push(make_pair(w[i],i));}
}
}
int main()
{
read(n);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{read(mp[i][j]);if(i==j) mp[i][j]=INF;}
Prim();
printf("%d",sum);
return ;
}

最新文章

  1. Windows Phone 的 TextBox 的实现 PropertyChanged
  2. UIKit - scrollView缩放、滚动
  3. VS2008 工程中部分文件不参与编译 从生成中排除【Worldsing笔记】
  4. KAFKA分布式消息系统
  5. 从CR线下活动学到的:如何组织一个小的线下活动
  6. SQL Server阻止了对组件xp_cmdshell过程的解决方案
  7. android studio c++ 自动补全
  8. 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"
  9. Learning React Native笔记
  10. Lucene教程 -------(一、初始Lucene)
  11. Python Selenium之异常处理
  12. Python函数默认参数的陷阱
  13. java中线程的三种实现方式
  14. HDU 1026(迷宫 BFS+打印)
  15. Miller Rabin素数检测
  16. P2731 骑马修栅栏 欧拉函数
  17. 第三部分:Android 应用程序接口指南---第二节:UI---第十一章 样式和主题
  18. Xcode连接TFS Git用户名和密码不正确解决方案
  19. Lua和C++交互 学习记录之五:全局数组交互
  20. PyCharm中的Console自动换行

热门文章

  1. 使用yarn代替npm
  2. C# WPF 仿QQ靠近屏幕上方自动缩起功能实现
  3. 超高频率问题之信息: Illegal access: this web application instance has been stopped already. Could not load . The eventual following stack trace is caused by an error thrown for debugging purposes as well as
  4. 在Vmware安装虚拟机WindowsServer 2003
  5. Django 的学习(1) 从建立到数据库操作
  6. Leetcode74. Search a 2D Matrix搜索二维矩阵
  7. sklearn之特征提取(文本特征)
  8. YouTube上最受欢迎的十大机器学习视频(最新)
  9. [Vue CLI 3] 插件开发之 registerCommand 到底做了什么
  10. 计算机组成原理作业一 熟悉MIPS指令