首页 技术 正文
技术 2022年11月13日
0 收藏 319 点赞 2,555 浏览 1477 个字

Ice_cream’s world III

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 576    Accepted Submission(s): 185

Problem Descriptionice_cream’s world becomes stronger and stronger; every road is built as undirected. The queen enjoys traveling around her world; the queen’s requirement is like II problem, beautifies the roads, by which there are some ways from every city to the capital. The project’s cost should be as less as better. InputEvery case have two integers N and M (N<=1000, M<=10000) meaning N cities and M roads, the cities numbered 0…N-1, following N lines, each line contain three integers S, T and C, meaning S connected with T have a road will cost C. OutputIf Wiskey can’t satisfy the queen’s requirement, you must be output “impossible”, otherwise, print the minimum cost in this project. After every case print one blank. Sample Input2 10 1 104 0 Sample Output10impossible 思路:prime,考虑重边!!!AC代码:

 #include<stdio.h>
#include<string.h>
int map[][],dist[];
int vis[],n;
void init1()
{
int i,j;
for(i = ;i < n;i ++)
{
for(j = ;j < n;j ++)
{
if(i != j)
map[i][j] = << ;
}
}
}
void init2()
{
int i;
memset(vis,,sizeof(vis));
for(i = ;i < n;i ++)
dist[i] = map[][i];
}
int main()
{
int m,i,j,k,cnt;
int min,len,sum,a,b;
while(~scanf("%d%d",&n,&m))
{
init1();
sum = cnt = ;
while(m--)
{
scanf("%d%d%d",&a,&b,&len);
if(len < map[a][b])
map[a][b] = map[b][a] = len;
}
init2();
vis[] = ;
for(i = ;i < n;i ++)
{
min = << ;
for(j = ;j < n;j ++)
{
if(!vis[j] && min > dist[j])
{
min = dist[j];
k = j;
}
}
vis[k] = ;
if(min != << )
{
cnt++;
sum += min;
}
for(j = ;j < n;j ++)
{
if(!vis[j] && dist[j] > map[k][j])
dist[j] = map[k][j];
}
}
if(cnt == n-)
printf("%d\n\n",sum);
else
printf("impossible\n\n");
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905