使用unordered_map比手写hash或者去重方便太多了!
以下是使用unordered_map实现离散化的核心代码
int x, y, z, xx, yy;
int sum = 0, c1 = 0, c2 = 0;
for(int i = 1; i <= n; i++)
{
scanf("%lld%lld%d", &x, &y, &z);
if(!mp.count(x))
mp[x] = ++num;
if(!mp.count(y))
mp[y] = ++num;
xx = mp[x], yy = mp[y];
if(z == 1)
eq[++c1] = (node){xx, yy};
else
ueq[++c2] = (node){xx, yy};
}