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 ...
随机推荐
- total commander相关设置
一. 中文语言包 在官方网站上提供有简体中文语言包,下面的说明以此为准.下载的语言包放至Total Commander安装目录下的Language子目录中.从菜单“Configuration”→“Op ...
- 用JAVA代码实现验证邮箱地址是否符合
public class Test{ public static void main(String[] args){ Test t = new Test(); String email = " ...
- jquery 常用类别选择器
1.$('#showDiv'): id选择器,相当于javascript中的documentgetElementById("showDiv"); 2.$("onecla ...
- smarty模版出现错误提示出现了不期望的字符
2013年7月5日 08:38:49 提示 unexpected "字符或字符串" 查找前边的代码,看是否有字符串单引号或双引号没有成对出现的情况
- java用代理访问
Properties prop = System.getProperties(); prop.setProperty("http.proxyHost", "localho ...
- 【Python爬虫】入门知识
爬虫基本知识 这阵子需要用爬虫做点事情,于是系统的学习了一下python爬虫,觉得还挺有意思的,比我想象中的能干更多的事情,这里记录下学习的经历. 网上有关爬虫的资料特别多,写的都挺复杂的,我这里不打 ...
- AsyncHttpClient
package com.jingle.httpstudy; import org.apache.http.Header; import android.app.Activity; import ...
- InnoDB引擎的索引和存储结构
在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的.而MySql数据库提供了多种存储引擎.用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据 ...
- web页面自适应手机屏幕宽度
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...
- 浅析 Java Thread.join()
转自:http://blog.csdn.net/bzwm/article/details/3881392 一.在研究join的用法之前,先明确两件事情. 1.join方法定义在Thread类中,则调用 ...