POJ 2421
#include<iostream>
#include<stdio.h>
#define MAXN 500
#define inf 100000000
using namespace std;
int pre[MAXN];
int _m[MAXN][MAXN];
int low_cost[MAXN];
int edge[][];
int q;
int w;
int prime(int n);
int main()
{
//freopen("acm.acm","r",stdin);
int num;
int i;
int j;
int u;
int v;
cin>>num;
for(i = ; i < num; ++ i)
{
for(j = ; j < num; ++ j)
{
cin>>_m[i][j];
}
}
cin>>q;
for(i = ; i < q; ++ i)
{
cin>>u>>v;
-- u;
-- v;
_m[u][v] = -;
_m[v][u] = -;
}
w = ;
cout<<prime(num) + w<<endl;
} int prime(int n)
{
int i;
int j;
int k;
int sum = ;
int min;
for(i = ; i < n; ++ i)
{
low_cost[i] = _m[][i];
pre[i] = ;
}
for(i = ; i < n; ++ i)
{
min = inf;
for(j = ; j < n; ++ j)
{
if(low_cost[j]&&low_cost[j] < min)
{
k = j;
min = low_cost[j];
}
}
if(low_cost[k] == -)
++ w;
sum += low_cost[k];
low_cost[k] = ;
for(j = ; j < n; ++ j)
{
if(_m[k][j] < low_cost[j] && low_cost[j])
{
low_cost[j] = _m[k][j];
pre[j] = k;
}
}
}
return sum;
}
POJ 2421的更多相关文章
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题
poj 1251 && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E ...
- POJ 2421(prim)
http://poj.org/problem?id=2421 这个题和poj1258是一样的,只要在1258的基础上那么几行代码,就可以A,水. 题意:还是n连通问题,和1258不同的就是这个还有几条 ...
- poj 2421 Constructing Roads 解题报告
题目链接:http://poj.org/problem?id=2421 实际上又是考最小生成树的内容,也是用到kruskal算法.但稍稍有点不同的是,给出一些已连接的边,要在这些边存在的情况下,拓展出 ...
- (最小生成树)Constructing Roads -- poj -- 2421
链接: http://poj.org/problem?id=2421 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2113 ...
- Poj(2421),Prim最小生成树
题目链接:http://poj.org/problem?id=2421 最小生成树的变形,有的村庄已经连接了,就直接把他们的权值赋为0,一样的做最小生成树,Prim算法. #include <s ...
- POJ 2421 Constructing Roads
题意:要在n个城市之间建造公路,使城市之间能互相联通,告诉每个城市之间建公路的费用,和已经建好的公路,求最小费用. 解法:最小生成树.先把已经建好的边加进去再跑kruskal或者prim什么的. 代码 ...
- POJ 2421 Constructing Roads (最小生成树)
Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D Description There ar ...
- [kuangbin带你飞]专题六 最小生成树 POJ 2421 Constructing Roads
给一个n个点的完全图 再给你m条道路已经修好 问你还需要修多长的路才能让所有村子互通 将给的m个点的路重新加权值为零的边到边集里 然后求最小生成树 #include<cstdio> #in ...
- POJ - 2421 Constructing Roads 【最小生成树Kruscal】
Constructing Roads Description There are N villages, which are numbered from 1 to N, and you should ...
随机推荐
- ThinkPHP redirect 传参
重定向带参 $this->redirect('pay/under_line_success',array('order_id'=>$stuInfo),5,'页面跳转中….'); 第一个参数 ...
- oracle远程连接
1.1.1 修改文件: 1.1.2 修改net Manager(可省略) 1.1.3 修改任何都需要重启oracle监听和启动服务
- vue 开发系列(六) 企业微信整合
概述 手机端程序可以和企业微信进行整合,我们也可以使用企业微信JSSDK功能,实现一些原生的功能. 整合步骤 在整合之前需要阅读 整合步骤. http://work.weixin.qq.com/api ...
- (19)3 moons and a planet that could have alien life
https://www.ted.com/talks/james_green_3_moons_and_a_planet_that_could_have_alien_life/transcript00:1 ...
- hashable/iterable与orderable
################ # hashable协议 # ################ # 一个对象能被称为hashable,它必须实现__hash__与_eq__方法: >>& ...
- 第22章:MongoDB-聚合操作--聚合管道--$out
①$out $out:利用此操作可以将查询结果输出到指定的集合里面. ②范例:将投影的结果输出到集合里
- ASP.NET 日志组件Smart.LogNet.DLL 引用即可写入日志及读取日志
借助LogNet组件,以后查看站点日志,再也不用去服务器下载了 日志组件:LogNet.DLL ,引用即可使用 写入方法: 1.LogNet.Log.WriteLog("日志标题" ...
- leetcode - [7]Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...
- Alpha阶段敏捷冲刺(二)
1.提供当天站立式会议照片一张. 2.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中: 昨天已完成的工作. 祁泽文:上网了解了艾宾浩斯遗忘曲线算法. 徐璐琳:找交互模块的源 ...
- dropzone 上传插件
dropzone dropzone.js是一个可预览的上传文件工具,不依赖任何框架(如jQuery),且具有可定制化.实现文件拖拽上传,提供AJAX异步上传功能. 1. html文件 dropzone ...