Codevs 1380 Prom without a boss

Source: Internet
Author: User

Basic tree-type DP. DP[I][J] I means someone, J says the man is coming. Transfer equation See procedure.

Note Pre-processing: First start all dp[i][1] for the given weight. First the people who have no subordinates into the team.

#include <iostream> #include <cstdio> #include <cstring> #include <queue>using namespace std; int n,r[6005],fath[6005],num[6005];int dp[6005][3];void BFS () {queue <int> q;for (int i=1;i<=n;i++) if (num[i]= =0) Q.push (i), while (!q.empty ()) {int Head=q.front (); Q.pop ();DP [Fath[head]][0]+=max (dp[head][0],dp[head][1]);DP [ Fath[head]][1]+=dp[head][0];num[fath[head]]--;if (num[fath[head]]==0) Q.push (Fath[head]);}} int main () {memset (num,0,sizeof (num)), scanf ("%d", &n), for (int i=1;i<=n;i++) {scanf ("%d", &r[i]);DP [i][1]= R[i];} for (int i=1;i<=n-1;i++) {int x,y;scanf ("%d%d", &x,&y); fath[x]=y;num[y]++;} int yjq_naive,cx_ak;scanf ("%d%d", &yjq_naive,&cx_ak); BFS (); int maxn=0;for (int i=1;i<=n;i++) for (int j=0;j <=1;j++) Maxn=max (Maxn,dp[i][j]);p rintf ("%d\n", MAXN); return 0;}

Codevs 1380 no boss's prom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.