During the training competition, I read the wrong question and thought that there were two different departments on both sides of the symbol. I thought that I had to use and check the set to solve the conflict. The result was a numerical value on the right. In fact, after the upper and lower bounds were initialized, DFS again. While updating the lower bound of each department, you can determine the contradiction.
Spy's work
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 802 accepted submission (s): 252
Problem descriptioni'm a manager of a large trading company, called ACM, and responsible for the market research. recently, another trading company, called ICPC, is set up suddenly. it's obvious that we are the competitor to each other now!
To get some information about ICPC, I have learned a lot about it. ICPC has n staffs now (numbered from 1 to n, and boss is 1), and anybody has at most one superior. to increase the efficiency of the whole company, the company contains N executions and
Ith department is led by the ith staff. All subordinates of the ith staff are 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, the spy only gets some information about some orders: the sum of the salaries of staff s working for the ith Department
Is 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 is telling a lie to us, that is to say, there will be some conflicts in the information. so I invite you, the talented programmer, to help me check the correction of the information. pay attention, my dear friend,
Each staff of ICPC will always get a salary even if it just 1 dollar!
Inputthere are multiple test cases.
The first line is an integer n. (1 <= n <= 10,000)
Each line I from 2 to n lines contains an integer x indicating the Xth staff is the ith staff's superior (x <I ).
The next line contains an integer m indicating the number of information from SPY. (1 <= m <= 10,000)
The next M lines have the form like (x <(> OR =) W), indicating the sum of the Xth department is less than (more than or equal) W (1 <= W <= 100,000,000)
Outputfor each test case, output "true" if the information has no confliction; otherwise output "lie ".
Sample Input
5113331 <63 = 42 = 25113331> 53 = 42 = 2
Sample output
Lietrue
# Include <iostream> # include <cstring> # include <string> # include <cstdio> using namespace STD; # define maxn 11000 # define INF 0x3fff3fstruct edges {int V, next ;} edge [22000]; int N; int vis [maxn], head [maxn], en; int L [maxn], U [maxn]; void add (int u, int v) {edge [En]. V = V; edge [En]. next = head [u]; head [u] = EN ++; edge [En]. V = u; edge [En]. next = head [v]; head [v] = EN ++;} bool DFS (int x) {vis [x] = 1; if (L [x]> U [x]) return false; in T CNT = 0, low = 0; For (INT I = head [X]; I! =-1; I = edge [I]. Next) {int to = edge [I]. V; If (vis [to]) continue; CNT ++; If (! DFS (to) return false; low + = L [to];} If (CNT = 0) return true; L [x] = max (L [X], low + 1); If (L [x]> U [x]) return false; return true;} int main () {int X, Y, M; char op [8]; while (~ Scanf ("% d", & N) {memset (Head,-1, sizeof (head); en = 0; For (INT I = 2; I <= N; I ++) {scanf ("% d", & X); add (x, I) ;}for (INT I = 1; I <= N; I ++) {L [I] = 1; U [I] = inf;} scanf ("% d", & M ); for (INT I = 0; I <m; I ++) {scanf ("% d % S % d", & X, op, & Y ); if (OP [0] = '<') U [x] = Y-1; else if (OP [0] = '> ') L [x] = Y + 1; else l [x] = U [x] = y;} memset (VIS, 0, sizeof (VIS )); if (DFS (1) printf ("True \ n"); else printf ("Lie \ n") ;}return 0 ;}