日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > poj 3140 Contestants Division (樹形dp)

poj 3140 Contestants Division (樹形dp)

來源:程序員人生   發布時間:2015-06-11 08:37:02 閱讀次數:2646次

Contestants Division
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8544   Accepted: 2439

Description

In the new ACM-ICPC Regional Contest, a special monitoring and submitting system will be set up, and students will be able to compete at their own universities. However there’s one problem. Due to the high cost of the new judging system, the organizing committee can only afford to set the system up such that there will be only one way to transfer information from one university to another without passing the same university twice. The contestants will be divided into two connected regions, and the difference between the total numbers of students from two regions should be minimized. Can you help the juries to find the minimum difference?

Input

There are multiple test cases in the input file. Each test case starts with two integers N and M, (1 ≤ N ≤ 100000, 1 ≤ M ≤ 1000000), the number of universities and the number of direct communication line set up by the committee, respectively. Universities are numbered from 1 to N. The next line has N integers, the Kth integer is equal to the number of students in university numbered K. The number of students in any university does not exceed 100000000. Each of the following M lines has two integers st, and describes a communication line connecting university s and university t. All communication lines of this new system are bidirectional.

N = 0, M = 0 indicates the end of input and should not be processed by your program.

Output

For every test case, output one integer, the minimum absolute difference of students between two regions in the format as indicated in the sample output.

Sample Input

7 6 1 1 1 1 1 1 1 1 2 2 7 3 7 4 6 6 2 5 7 0 0

Sample Output

Case 1: 1

類似 poj 2378

刪邊,求刪去某條邊后兩個分支的最小差異值;注意數據范圍。

#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> using namespace std; #define ll long long #define N 110000 #define mem(a,t) memset(a,t,sizeof(a)) const int inf=1000005; int cnt,n; struct node { int v,next; }e[N*20]; int head[N]; ll num[N]; ll ans,sum; void add(int u,int v) { e[cnt].v=v; e[cnt].next=head[u]; head[u]=cnt++; } void dfs(int u,int len,int fa) { int i,v; for(i=head[u];i!=⑴;i=e[i].next) { v=e[i].v; if(v!=fa) { dfs(v,len+1,u); num[u]+=num[v]; } } ll t=sum⑵*num[u]; if(t<0) t*=⑴; if(t<ans) ans=t; } int main() { //freopen("in.txt","r",stdin); int i,u,v,m,cas=1; while(scanf("%d%d",&n,&m),n||m) { for(i=1,sum=0;i<=n;i++) { scanf("%lld",&num[i]); sum+=num[i]; } cnt=0; mem(head,⑴); for(i=0;i<m;i++) { scanf("%d%d",&u,&v); add(u,v); add(v,u); } ans=sum; dfs(1,0,⑴); printf("Case %d: %lld ",cas++,ans); } return 0; }




生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 日韩精品视频中文字幕 | 日韩欧美字幕 | 久9热这里只有精品视频 | 成人欧美一区二区三区在线播放 | 久久久国产一区 | www.黄.com | 国产一区二区三区免费观看网站上 | 久久女| 二区三区视频 | 久久久精品网站 | 精品视频在线观看一区二区三区 | 久久久久久九九 | 91午夜在线| 黄色一极毛片 | 日韩在线免费视频 | 精品66| 男女在线观看视频 | 岛国片在线免费观看 | 亚洲高清色图 | 国产精品欧美一区二区 | 日韩 欧美 中文 | 91日韩在线 | 亚洲午夜免费视频 | 成人av在线网 | 欧美日本韩国一区二区三区 | 91在线精品视频 | 久久机这里只有精品 | 国产成人精品aa毛片 | 九九精品久久 | 圆产精品久久久久久久久久久 | 91精品一区二区三区蜜桃 | a在线免费观看 | 国产白浆在线观看 | 国产精品成人在线 | 日韩黄色小视频 | 黄色高清网站 | 99久久99久久精品国产片果冻 | 国产一级成人 | 国产精品三级久久久久久电影 | 99久久九九 | 午夜性视频 |