标签:keep php integer big lld i++ -128 pre atom
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1893 Accepted Submission(s): 809
#include <bits/stdc++.h> #define inf 0x3f3f3f3f #define met(a,b) memset(a,b,sizeof a) #define pb push_back #define mp make_pair #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define inf 0x3f3f3f3f using namespace std; typedef long long ll; const int N = 1e6+50;; const int M = 255; const int mod = 19260817; const int mo=123; const double pi= acos(-1.0); typedef pair<int,int>pii; int n,k,cas; ll ans; int sz[N]; vector<pii>edg[N]; void dfs(int u,int fa){ sz[u]=1; for(auto e : edg[u]){ int v=e.first; int w=e.second; if(v==fa)continue; dfs(v,u); sz[u]+=sz[v]; ans+=1LL*w*min(sz[v],k); } } int main(){ //int T; //scanf("%d",&T); while(~scanf("%d%d",&n,&k)){ for(int i=1;i<=n;i++)edg[i].clear(); for(int i=1,u,v,w;i<n;i++){ scanf("%d%d%d",&u,&v,&w); edg[u].pb(mp(v,w));edg[v].pb(mp(u,w)); } ans=0; dfs(1,0); printf("%lld\n",ans); } return 0; }
HDU 6060 RXD and dividing(dfs 思维)
标签:keep php integer big lld i++ -128 pre atom
原文地址:http://www.cnblogs.com/jianrenfang/p/7567484.html