您的位置:首页 > 其它

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










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;



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: