简单题
代码:
#include#include #include using namespace std;vector edge[100001];long long value[100001];int v[100001];long long dp[100001];long long n,m;long long ok(long long s){ if(s<0) return -s; return s;}long long solve(long long s){ long long i; v[s]++; dp[s]=value[s]; for(i=0;i >n>>m) { k++;if(n==0&&m==0) return ; for(i=1;i<=n;i++) edge[i].clear(); long long sum=0; memset(v,0,sizeof(v)); for(i=1;i<=n;i++) { cin>>value[i]; sum+=value[i]; } for(i=1;i<=m;i++) { cin>>s>>t; edge[s].push_back(t); edge[t].push_back(s); } solve(1); long long ans=ok(sum-2*dp[1]); for(i=2;i<=n;i++) if(ans>ok(sum-2*dp[i])) ans=ok(sum-2*dp[i]); printf("Case %lld: %lld\n",k,ans); } }int main(){ read(); return 0;}