poj 1258
来源:互联网 发布:淘宝客如何招代理 编辑:程序博客网 时间:2024/06/08 05:58
水题
改了改poj 2458,直接交了
#include<cstdio> #include<iostream> #include<cstring> #include<iostream> using namespace std; const int INF=0x3f3f3f; bool used[505]; int mincost[505]; int cost[505][505]; int prim(int n) { for(int i=1;i<=n;i++) mincost[i]=INF; memset(used,false,sizeof(used)); int res=0; mincost[1]=0; for(int i=1;i<=n;i++){ int v=-1; for(int u=1;u<=n;u++) if(!used[u]&&(v==-1||mincost[u]<mincost[v])) v=u; if(v==-1) break; used[v]=true; res+=mincost[v]; for(int u=1;u<=n;u++) mincost[u]=min(mincost[u],cost[u][v]); } return res; } int main() { int n,dd; while(~scanf("%d",&n)){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ scanf("%d",&dd); cost[i][j]=dd; } printf("%d\n",prim(n)); } }
阅读全文
0 0
- Poj 1258
- poj 1258
- POJ 1258
- poj 1258
- POJ 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ - 1258
- html页面数据抓取
- 图像语义分割的总结和资源推荐
- 归并排序
- 监控 Linux 性能的 18 个命令行工具
- java activeMQ消息的发送与接收
- poj 1258
- fragment解析
- ajax 异步获取导致的错误
- ssm框架的搭建
- Word-docx文件图片信息格式分析
- COBIT信息及相关技术控制目标认证
- php笔记-1
- Codeforces Round #429 (Div2) C
- AD里的app_id概念