ZZULI 1497 Reading Books
2012-12-05 17:08
337 查看
Reading
Books
Time Limit:1000MS Memory
Limit:65536KTotal Submit:15 Accepted:2
Description
In the summer vacation,LRJ
wants to improve himself incomputer science.So he finds out Nbooks
of computer science in the school library.The books are numbered
from 0 to N-1.To finish reading the i-th book,it takes LRJ time[i] minutes.But
some books are similar in the content. If the i-th book and the
j-th book are similar,then if LRJ has finished reading the i-th
book,it will take him only [time[j]/2] minutes to finish reading
the j-th book.Of course if LRJ has finished reading the j-th
book,it will take him only [time[i]/2] minutes to finish reading
the i-th book,Now you are asked to tell LRJ the minimal total time
to finish reading all the N books.Input
The first line contains
two integers N (0≤N≤100)and M(0≤M≤N(N-1)/2).N is the total number
of books.M is thenumber of pairs which are similar.Then the
following N lines describe
time[0],time[1],…,time[N-1](1≤time[i]≤10^5).Next comes M lines ,each contains two integer (i,j),indicating that
the i-th book and the j-th book are similar.Input is ended by N=0
and M=0.Output
For each test case ,just
output the minimal total time on a single line.Sample
Input
Sample
Output
Books
Time Limit:1000MS Memory
Limit:65536KTotal Submit:15 Accepted:2
Description
In the summer vacation,LRJ
wants to improve himself incomputer science.So he finds out Nbooks
of computer science in the school library.The books are numbered
from 0 to N-1.To finish reading the i-th book,it takes LRJ time[i] minutes.But
some books are similar in the content. If the i-th book and the
j-th book are similar,then if LRJ has finished reading the i-th
book,it will take him only [time[j]/2] minutes to finish reading
the j-th book.Of course if LRJ has finished reading the j-th
book,it will take him only [time[i]/2] minutes to finish reading
the i-th book,Now you are asked to tell LRJ the minimal total time
to finish reading all the N books.Input
The first line contains
two integers N (0≤N≤100)and M(0≤M≤N(N-1)/2).N is the total number
of books.M is thenumber of pairs which are similar.Then the
following N lines describe
time[0],time[1],…,time[N-1](1≤time[i]≤10^5).Next comes M lines ,each contains two integer (i,j),indicating that
the i-th book and the j-th book are similar.Input is ended by N=0
and M=0.Output
For each test case ,just
output the minimal total time on a single line.Sample
Input
Sample
Output
int i;
if(flag ==1)return;
flag =1;
if(min>time )min=time ;
for(i=1;i<=num [0];i++)
dfs(num [i]);
int m,n,i,a,b;
while(scanf("%d%d",&m,&n),m!=0||n!=0)
{
memset(num,0,sizeof(num));
memset(flag,0,sizeof(flag));
sum=0;
for(i=0;i<m;i++)
{
scanf("%d",&time[i]);
sum+=time[i]/2;
}
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
num[a][++num[a][0]]=b;
num[b][++num[b][0]]=a;
}
for(i=0;i<m;i++)
{
if(flag[i]==0)
{
min=time[i];
dfs(i);
sum=sum-min/2+min;
}
}
printf("%d\n",sum);
}
return 0;
if(n!=num )
n=root(num );
return n;
int m,n,i,sum,a,b,time[120];
while(scanf("%d%d",&m,&n),m!=0||n!=0)
{
for(i=0;i<m;i++)
{
scanf("%d",&time[i]);
num[i]=i;
}
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
a=root(a);
b=root(b);
if(time[a]<time[b])
num[b]=a;
else num[a]=b;
}
sum=0;
for(i=0;i<m;i++)
{
if(num[i]==i)
sum+=time[i];
else sum+=time[i]/2;
}
printf("%d\n",sum);
}
return 0;
相关文章推荐
- ZZULI 1208 二叉树(1)
- ZZULI_SummerPractice(5) ZOJ 194…
- ZZULI_SummerPractice(6) POJ 362…
- ZZULI_SUMMER_PRACTICE(7) 1172
- ZZULI 1595 Pills
- ZZULI 1209 二叉树(2)
- ZZULI_SummerPractice(6) POJ 270…
- ZZULI_SUMMER_PRACTICE(7) 1173
- ZZULI 1596 Assign the task(暴力…
- ZZULI 1615 easy or puzzle ?(字…
- ZZULI 1210 二叉树(3)
- ZZULI_SummerPractice(6) POJ 329…
- ZZULI_SUMMER_PRACTICE(7) 1175 …
- ZZULI 1597 Maze(果断DFS)
- ZZULI 1616(POJ 2243||HDU 1372)…
- ZZULI 1480 图论的起源
- ZZULI_SUMMER_PRACTICE(7) 1176 …
- ZZULI_TEAM_PRACTICE(1) HDU 1251…
- ZZULI 1599(POJ 1975)Median Wei…
- ZZULI 1617 (HDU 1686)Oulipo (…