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]的更多相关文章

  1. [ACM] hdu 4418 Time travel (高斯消元求期望)

    Time travel Problem Description Agent K is one of the greatest agents in a secret organization calle ...

  2. HDU5441 Travel 离线并查集

    Travel Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, ...

  3. Problem C: [noip2016十连测第五场]travel (构造+贪心)

    题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...

  4. HDU 6325 Problem G. Interstellar Travel(凸包)

    题意: 给你n个点,第一个点一定是(0,0),最后一个点纵坐标yn一定是0,中间的点的横坐标一定都是在(0,xn)之间的 然后从第一个点开始飞行,每次飞到下一个点j,你花费的价值就是xi*yj-xj* ...

  5. HDU - Travel

    Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...

  6. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. ural 1286. Starship Travel

    1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...

  8. hdu 5441 travel 离线+带权并查集

    Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...

  9. Codeforces Beta Round #51 A. Flea travel 水题

    A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...

随机推荐

  1. [POJ1050]To the Max

    [POJ1050]To the Max 试题描述 Given a two-dimensional array of positive and negative integers, a sub-rect ...

  2. 通过IIS调试ASP.NET项目

    当我们使用Visual Studio调试的时候,通常我们会选择VS自带的ASP.NET Developerment Server(也是默认选项),当第一次调试的时候(按F5或Ctrl+F5不调试直接打 ...

  3. C# params关键字

    params数组的要点 C#开发语言中 params 是关键字,可以指定在参数数目可变处采用参数的方法参数.在函数的参数数目可变而执行的代码差异很小的时候很有用! class Program { st ...

  4. NYOJ 106背包问题

    http://acm.nyist.net/JudgeOnline/problem.php?pid=106 背包问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现 ...

  5. 【Python】Django 如何直接返回404 被 curl,wget 捕获到

    代码示例: from django.http import Http404, HttpResponseNotFound #raise Http404(filename) return HttpResp ...

  6. 【转】mysql忘记root密码的解决方法

    本文收集于本人的笔记本,由于找不到原文出处.在此省略,如哪位知道可以联系我加上. 方法一:在windows下:1.打开命令行(DOS)窗口,停止mysql服务: net stop mysql 2.在D ...

  7. Sybase IQ导出文件的几种方式

    IQ有四种方法,将表的数据导出为文本文件:1.重定向 SELECT * FROM TABLE1 ># D:MYDATATABLE1.TXT -- 文件生成在执行语句的客户端上 2.通过选项导出 ...

  8. Java for LeetCode 144 Binary Tree Preorder Traversal

    Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...

  9. JavaScript设计模式 - 迭代器模式

    迭代器模式是指提供一种方法顺序访问一个聚合对象中的各个元素,而又不需要暴露该对象的内部表示. 迭代器模式可以把迭代的过程从业务逻辑中分离出来,在使用迭代器模式之后,即使不关心对象的内部构造,也可以按顺 ...

  10. CodeForces - 417E(随机数)

    Square Table Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...