Travel Problem[SZU_K28]
Description
After SzuHope take part in the 36th ACMICPC Asia Chendu Reginal Contest. Then go to QingChengShan for fun. QCS has many spot as the picture following, each spot has its unique value for SzuHope, they will get the value just once if and only if they had been there. From one spot will exists some roads to other spots, it means that one road link two spots without direction. SzuHope can choose any spot to travel at beginning, but then they can go to next spot only by roads. Can you help them make the travel’s total value biggest?
Input
There are less than 100 test cases. For each case, the first line has two numbers M,N.describe the number of spots and roads(1<=N<=1000, 0<=M<=N*N) , the spots are numbered with 1,2,3…N; the second line has N numbers describe the value xi of each spot(0<xi<1000); the next M line, each line has two numbers U,V(1<= U,V<=N) means U,V is connected. 0 0 for end.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the result.
Sample Input
0 1
5
1 3
1 3 2
1 3
0 0
Sample Output
Case 1:
5
Case 2:
3
#include<stdio.h>
#include<string.h>
int s[1025],father[1025],w[1025];
int getfather(int v)
{
if (father[v]==v) return father[v];
father[v]=getfather(father[v]);
return father[v];
}
void merge(int u,int v)
{
u=getfather(u);
v=getfather(v);
father[u]=v;
}
int main()
{
int N,M,i,cas=0;
while (scanf("%d%d",&M,&N)!=EOF && M+N)
{
cas++;
printf("Case %d:\n",cas);
for (i=1;i<=N;i++) scanf("%d",&w[i]);
for (i=1;i<=N;i++) father[i]=i;
for (i=1;i<=M;i++)
{
int u,v;
scanf("%d%d",&u,&v);
merge(u,v);
}
for (i=1;i<=N;i++) father[i]=getfather(i);
memset(s,0,sizeof(s));
for (i=1;i<=N;i++) s[father[i]]+=w[i];
int Max=0;
for (i=1;i<=N;i++)
if (s[i]>Max) Max=s[i];
printf("%d\n",Max);
}
return 0;
}
Travel Problem[SZU_K28]的更多相关文章
- [ACM] hdu 4418 Time travel (高斯消元求期望)
Time travel Problem Description Agent K is one of the greatest agents in a secret organization calle ...
- HDU5441 Travel 离线并查集
Travel Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, ...
- Problem C: [noip2016十连测第五场]travel (构造+贪心)
题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...
- HDU 6325 Problem G. Interstellar Travel(凸包)
题意: 给你n个点,第一个点一定是(0,0),最后一个点纵坐标yn一定是0,中间的点的横坐标一定都是在(0,xn)之间的 然后从第一个点开始飞行,每次飞到下一个点j,你花费的价值就是xi*yj-xj* ...
- HDU - Travel
Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- ural 1286. Starship Travel
1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...
- hdu 5441 travel 离线+带权并查集
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
随机推荐
- JdbcTemplate三种常用回调方法
JdbcTemplate针对数据查询提供了多个重载的模板方法,你可以根据需要选用不同的模板方法. 如果你的查询很简单,仅仅是传入相应SQL或者相关参数,然后取得一个单一的结果,那么你可以选择如下一组便 ...
- 如何在linux中用命令产生一个范围内的随机数?
在shell中有一个环境变量RANDOM,它的范围是0--32767 如果我们想要产生0-25范围内的数,如何做呢?如下: $RANDOM%26 用这个环境变量对26取模,就可以得到最小是0,最大是2 ...
- 每天一个脚本解析day1==》《service xxxxx status》之service脚本解析
vim /sbin/service #!/bin/sh . /etc/init.d/functions #读取环境变量. VERSION="$(basename $0) ver. 0. ...
- 使用msgfmt编译多语言文件
msgfmt --statistics --verbose -o django.mo django.po
- MAC的OS X10.10更新以后进入用户界面就死机
我用的是搜狗输入法,所以把搜狗卸载就好了.(注意是卸载,不是单纯的从输入源里移除) 下载一个搜狗输入法的DMG,打开后选择卸载搜狗输入法. 转自: http://zhidao.baidu.com/qu ...
- 【转】Solr从数据库导入数据(DIH)
本文转自:http://blog.csdn.net/xiaoyu714543065/article/details/11849115 一. 数据导入(DataImportHandler-DIH) DI ...
- Java for LeetCode 149 Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- FZU 2140 Forever 0.5 (几何构造)
Forever 0.5 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 用scanf输入字符串
char s[10];scanf("%s",s);改为scanf("%s",&s);也正确,为什么? 1 s与&s都表示地址,且值相等.2 s与 ...
- SQL 查询45题
表格代码 create table student ( sno ) primary key, sname ) not null, ssex ) not null, sbirthday datetime ...