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 ...
随机推荐
- 2018.11.18 bzoj2194: 快速傅立叶之二(fft)
传送门 模板题. 将bbb序列反过来然后上fftfftfft搞定. 代码: #include<bits/stdc++.h> #define ri register int using na ...
- AttributeError: type object 'testClass' has no attribute 'testMothod'
点击"Unittest for test_post_API.testClass"按钮,点击”Edit configuration...“,弹出对话框Run/Debug config ...
- 【转载】Impala和Hive的区别
Impala和Hive的关系 Impala是基于Hive的大数据实时分析查询引擎,直接使用Hive的元数据库Metadata,意味着impala元数据都存储在Hive的metastore中.并且im ...
- create table b1 as select * from b建表锁表测试
A: create table a1 like a; insert into a1 as select * from a; B: create table b1 as select * from b; ...
- WordPaster-KesionCMS V8整合教程
1.上传WordPaster文件夹 2.上传ckeditor3x插件文件夹 4.修改ckeditor编辑器的config.js文件,启用插件,在工具栏中增加插件按钮 5.在文章页面增加插件初始化代码 ...
- 利用nginx打造个人简历网页
1.下载nginx nginx官方网址:http://nginx.org/ 2.下载和解压 #下载:[root@iZwz9cl4i8oy1reej7o8pmZ soft]# wget http://n ...
- Docker Compose部署lnmp
参考:https://github.com/micooz/docker-lnmp 一.简介 使用Dcoekr镜像部署lnmp(Linux.Nginx.MySQL.PHP7). 1.1 结构 app └ ...
- (转)VmWare下安装CentOS6图文安装教程
转自:http://www.cnblogs.com/seesea125/archive/2012/02/25/2368255.html 第一次使用VmWare和CentOS6,中间遇到不少问题,记性不 ...
- android testview + listview 整体滚动刷新
listview滚动刷新不再讲述怎么实现 因为想实现整体滚动的效果,初始计划scrollView嵌套listview实现. 问题一:scrollview嵌套listview时,listview只能显示 ...
- 查找对端mac地址
1.ping对端mac: 2.arp命令查找: