Question: Give a tree, give the weight relationship of some sub-trees, and ask if there is a conflict
Initially, the lower limit of all nodes and subtree is 1, and the upper limit may be unknown.
Then, update the upper and lower bounds through the given inequality, then perform tree-like DP, and update the lower bounds of the parent node through the lower bounds of the child.
Determine if there are any conflicts
Note that the minimum weight of the current node is 1, and the lower limit of the node is the sum of + 1
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <map>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <algorithm>
# Include <set>
# Define inf 110000000
# Define M 10005
# Define N 10005
# Define Min (a, B) (a) <(B )? (A) (B ))
# Define Max (a, B) (a)> (B )? (A) (B ))
# Define pb (a) push_back ()
# Define mem (a, B) memset (a, B, sizeof ())
# Define LL long
# Define MOD 1000000007.
Using namespace std;
Struct Node {
Int v, next;
} Edge [N * 2];
Int n, start [N], tot;
Int up [N], low [N];
Void addedge (int u, int v ){
Edge [tot]. v = v;
Edge [tot]. next = start [u];
Start [u] = tot ++;
}
Void _ addedge (int u, int v ){
Addedge (u, v );
Addedge (v, u );
}
Bool ans;
Void dfs (int u, int pre ){
If (ans) return;
If (up [u]! =-1 & low [u]> up [u]) {ans = true; return ;}
Int tmp = 0;
Int leaf = 1;
For (int I = start [u]; I! =-1; I = edge [I]. next ){
Int v = edge [I]. v;
If (v = pre) continue;
Dfs (v, u );
Leaf = 0;
Tmp + = low [v];
}
If (leaf) return;
Low [u] = max (tmp + 1, low [u]);
If (up [u]! =-1 & low [u]> up [u]) ans = true;
}
Int main (){
While (scanf ("% d", & n )! = EOF ){
Tot = 0; mem (start,-1 );
For (int I = 2; I <= n; I ++ ){
Int u;
Scanf ("% d", & u );
_ Addedge (u, I );
}
Int m;
For (int I = 1; I <= n; I ++) {low [I] = 1; up [I] =-1 ;}
Scanf ("% d", & m );
For (int I = 0; I <m; I ++ ){
Int u, w;
Char str [5];
Scanf ("% d % s % d", & u, str, & w );
If (str [0] = '<') up [u] = W-1;
Else if (str [0] = '>') low [u] = w + 1;
Else low [u] = up [u] = w;
}
Ans = false;
Dfs (1, 0 );
Puts (ans? "Lie": "True ");
}
Return 0;
}