Bzoj1202 -- with permission and query set + prefix and, bzoj1202 -- prefix
Http://www.lydsy.com/JudgeOnline/problem.php? Id = 1202
Note that s [I] = a [1] + a [2] +... + a [I], that is, s [I] is the prefix and. Then v [I] = s [f [I]-s [I], where f [I] is the father of I. For each read x, y, k, x and y are considered as nodes. If x and y are the same root nodes, because v [y]-v [x] = s [f [y]-s [y]-s [f [x]-s [x] and f [y] = f [x], therefore, v [y]-v [x] is the sum of the range [x, y]. Therefore, you only need to determine whether v [y]-v [x] is k. If the root nodes of x and y are different, merge the two nodes and update the information.
# Include <cstdio> # include <cstring> using namespace std; int n, I, j, m, f [101], w, x, y, k, v [101]; bool flag; int find (int x) {if (x = f [x]) return x; int tmp = f [x]; // record the original father f [x] = find (f [x]); v [x] + = v [tmp]; // update the node information return f [x];} bool union1 (int x, int y, int k) {int fx = find (x), fy = find (y ); if (fx = fy) {if (v [y]-v [x]! = K) return 0;} else {f [fy] = fx; v [fy] = k-v [y] + v [x]; // update node information} return 1;} int main () {scanf ("% d", & w); while (w --) {memset (v, 0, sizeof (v); flag = 0; scanf ("% d", & n, & m); for (I = 0; I <= n; I ++) f [I] = I; for (I = 1; I <= m; I ++) {scanf ("% d ", & x, & y, & k); if (! Flag &&! Union1 (x-1, y, k) flag = 1;} if (flag) printf ("false \ n"); else printf ("true \ n ");} return 0 ;}