题意:
给出m个区间和,询问是否有区间和和之前给出的矛盾
NOIp之前做过hdu3038.....
带权并查集维护到根的权值和,向左合并
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=1e6+;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int n, m, l, r, v;
int fa[N], val[N];
int find(int x) {
if(x == fa[x]) return x;
int root = find(fa[x]);
val[x] += val[fa[x]];
return fa[x] = root;
} int main() {
freopen("in", "r", stdin);
int T=read();
while(T--) {
n=read()+; m=read();
for(int i=; i<=n; i++) fa[i]=i, val[i]=;
int flag=;
for(int i=; i<=m; i++) {
l=read(); r=read()+; v=read();
if(!flag) continue;
int x = find(l), y = find(r); //printf("hi %d %d %d %d %d %d\n", l,r,x,y,val[l],val[r]);
if(x == y) {
if(val[r] - val[l] != v) flag = ;
} else fa[y] = x, val[y] = v - val[r] + val[l];
}
puts(flag ? "true" : "false");
}
}