记录编号 |
234212 |
评测结果 |
AAAAAAAAAA |
题目名称 |
读书 |
最终得分 |
100 |
用户昵称 |
Sky_miner |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.002 s |
提交时间 |
2016-03-07 16:02:08 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include<cstdio>
using namespace std;
const int maxn = 100 + 10 ;
struct Node{
int root;
int time;
bool key;
}G[maxn];
int ans;
int find(const int x){
if( G[x].root != x){
int r = G[x].root;
G[x].root = find(G[x].root);
if( G[x].key ) {
G[x].time = G[x].time>>1 ;
G[x].key = false ;
}
}
return G[x].root;
}
void work(const int &x,const int &y ){
int rx = find(x);
int ry = find(y);
if( rx != ry ){
if(G[rx].time > G[ry].time ){
G[rx].root = ry;
ans-=G[rx].time - (G[rx].time>>1);
G[rx].time = G[rx].time>>1;
G[rx].key = false;
}
else{
G[ry].root = rx;
ans-=G[ry].time - (G[ry].time>>1);
G[ry].time = G[ry].time>>1;
G[ry].key = false;
}
}
}
int main(){
int n,m;
#define Work
#ifdef Debug
freopen("C://Users//Administrator//Documents//test_in.txt","r",stdin);
freopen("C://Users//Administrator//Documents//test_out.txt","w",stdout);
#endif
#ifdef Work
freopen("reading.in","r",stdin );
freopen("reading.out","w",stdout);
#endif
while(scanf("%d%d",&n,&m) == 2 && ( m!=0 || n!=0 ) ){
ans = 0;
for(int i=1;i<=n;i++){
G[i].root = i;
scanf("%d",&G[i].time);
ans+= G[i].time;
G[i].key = true ;
}
int u,c;
//printf("--------->%d\n",m);
for(int i=1;i<=m;i++){
scanf("%d%d",&u,&c);
work(u+1,c+1);
}
printf("%d\n",ans);
}
return 0;
}