int fa[N << 1]; inlineintfind(int x){ return fa[x] = (fa[x] == x ? x : find(fa[x])); }
vector<int >mN[N << 1];
inlinevoidInput(){ read(n); for(int i = 1; i <= n; i++) { read(x[i], y[i], p[i]); vx.push_back(x[i]); vx.push_back(y[i]); } }
inlineboolCheck(int x, int y, int p){ int fx = find(x), fy = find(y); if(fx == fy) return p == 1; // must equal if(mN[fx].size() > mN[fy].size()) swap(fx, fy); for(auto &p : mN[fx]) { if(find(p) == fy) { return p == 0; // must not equal } } // then we need define two variable is equal or not if(p == 1) { fa[fx] = fy; // we are equal, so the variable not equal to you is also not equal to me for(auto &p : mN[fx]) { mN[fy].push_back(p); } mN[fx].clear(); } else { mN[fy].push_back(fx); mN[fx].push_back(fy); } return1; }