lli val = abs(val[x]-val[y]);
^ At this point, you've introduced a name "val", of type "long long int".
So "val[x]" is trying to index into a variable of type long long int!
Use a different name e.g.
lli value = abs(val[x]-val[y]);
if(value<=mid)
{
dsu.Union(x,y);
}