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 ...
随机推荐
- MySQL之扩展(触发器,存储过程等)
视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( SEL ...
- django-cms 代码研究(三)插件(plugs in)
插件(plugs in) djangocms支持的插件有: http://docs.django-cms.org/en/latest/basic_reference/plugin_reference. ...
- Linux 系统安全 抵御TCP的洪水
抵御TCP的洪水 分类: LINUX tcp_syn_retries :INTEGER默认值是5对 于一个新建连接,内核要发送多少个 SYN 连接请求才决定放弃.不应该大于255,默认值是5,对应于1 ...
- linux 下如何查看和踢除正在登陆的其它用户 ==>Linux下用于查看系统当前登录用户信息的4种方法
在linux系统中用pkill命令踢出在线登录用户 由于linux服务器允许多用户登录,公司很多人知道密码,工作造成一定的障碍 所以需要有时踢出指定的用户 1/#who 查出当前有那些终端登录(用 ...
- MVC ActionResult JsonResult
以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...
- poj 1833
http://poj.org/problem?id=1833 next_permutation这个函数是用来全排列的,按字典的序进行排列,当排列无后继的最大值时,会执行字典升序排列,相当于排序: 当排 ...
- Http 协议Header
Responses 部分 Header 解释 示例 Accept-Ranges 表明服务器是否支持指定范围请求及哪种类型的分段请求 Accept-Ranges: bytes Age 从原始服务器到代理 ...
- ARGB32 to YUV12 利用 SDL1.2 SDL_ttf 在视频表面输出文本
提示:ARGB alpha通道的A + 原YUV表面的y0 + 要写进去的y1 = 计算出新的y2. 计算公式为 ( y1 * a + y0 * ( 255 - a ) ) / 255 void rg ...
- codeforces 478B Random Teams 解题报告
题目链接:http://codeforces.com/problemset/problem/478/B 题目意思:有 n 个人,需要将这班人分成 m 个 组,每个组至少含有一个人,同一个组里的人两两可 ...
- C标签判断两个值是否相等
c标签判断两个值是否相等 Integer用:${user1.id eq user2.id}:int用:${user1.id == user2.id} 测试代码如下:<c:if test=&quo ...