HDU 4274 spy& #39; s work (water problem)

Source: Internet
Author: User

Spy ' s workTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1266 Accepted Submission (s): 388


Problem Descriptioni ' m a manager of a large trading company, called ACM, and responsible for the market. Recently, another trading company, called ICPC, was set up suddenly. It ' s obvious that we're the competitor to each other now!
To get some information about ICPC, I had learned a lot of it. ICPC have N staffs now (numbered from 1 to N, and Boss is 1), and anybody have at the most one superior. To increase the efficiency of the whole company, the company contains N departments and the ith department are led by the I TH staff. All subordinates of the ith staff is also belong to the ith department.
Last week, we hire a spy stealing into ICPC to get some information about salaries of staffs. Not getting the detail about each one and the spy only gets some information about some departments:the sum of the salaries of staff s working for the ith department are less than (more than or equal to) W. Although the some inaccurate information, we can also get some important intelligence from it.
Now I only concerned about whether the spy was telling a lie to us, that's to say, there would be some conflicts in the INF Ormation. So I invite your, the talented programmer, to help me check the correction of the information. Pay attention, my dear friend, each staff of ICPC would always get a salary even if it just 1 dollar!

Inputthere is multiple test cases.
The first line was an integer n. (1 <= N <= 10,000)
Each line I from 2 to N lines contains a integer x indicating the xth staff are the ith staff ' s superior (x<i).
The next line contains a integer M indicating the number of information from the spy. (1 <= M <= 10,000)
The next M lines has the form like (x < (> or =) w), indicating the sum of the Xth department are less than (more tha n or equal To) W (1 <= w <=100,000,000)

Outputfor each test case, output "True" If the information have no confliction; Otherwise output "Lie".

Sample Input
5113331 < = 42 = 2 = 25113331 > 53 =

Sample Output
Lietrue

Source2012 ACM/ICPC Asia Regional Changchun Online
recommendliuyiding | We have carefully selected several similar problems for you:4272 4277

pid=4273 "target=" _blank ">4273

pid=4270 "target=" _blank ">4270 4269 Test instructions: give you a tree.

Then tell you the range of the weights and values of a subtrees tree. Then ask if you have any contradictions. Ideas: Each node maintains two values Ns[i],nb[i] the weight range of the current subtree Ns[i]<=val<=nb[i] renewal of the father's range from son to Father level. The intermediate inference is whether the conflict. See the code for details:

#include <algorithm> #include <iostream> #include <string.h> #include <stdio.h>using namespace Std;const int maxn=10010;typedef Long long ll;const ll Inf=1e14;int fa[maxn];ll ns[maxn],nb[maxn],sz[maxn],ss[maxn],sb[    Maxn];int Main () {int n,i,x,m,w,flag;    Char op[10];        while (~SCANF ("%d", &n)) {fa[1]=flag=0;            for (i=1;i<=n;i++) {sz[i]=1;            Ns[i]=-inf,nb[i]=inf;        ss[i]=sb[i]=0;            } for (i=2;i<=n;i++) {scanf ("%d", &x);        Fa[i]=x;        } scanf ("%d", &m);            for (i=1;i<=m;i++) {scanf ("%d%s%d", &x,op,&w);            if (op[0]== ' = ') nb[x]=ns[x]=w;            else if (op[0]== ' < ') nb[x]=min (Nb[x], (LL) w-1);        else Ns[x]=max (Ns[x], (LL) w+1);            } for (i=n;i>=1;i--) {if (flag) break;            Ns[i]=max (Ns[i],sz[i]); Ifns[i]>nb[i]| |            Nb[i]<=ss[i]) flag=1;            Ns[i]=max (ns[i],ss[i]+1);            if (Ns[i]>nb[i]) flag=1;            Sz[fa[i]]+=sz[i];            Ss[fa[i]]+=ns[i];        Sb[fa[i]]+=nb[i];        } if (flag) printf ("lie\n");    else printf ("true\n"); } return 0;}


HDU 4274 spy& #39; s work (water problem)

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.