#include <map>
#include <list>
#include <fstream>
#include <iostream>
using namespace std;
#define N 100000 + 10
int T;
struct Node {
int i, j, e;
};
map<int, int> fa;
int find_root(int x) {
if (fa[x] != x)
fa[x] = find_root(fa[x]);
return fa[x];
}
int main() {
// fstream in("_____.in", ios::in);
// fstream out("_____.out", ios::out);
scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
bool f = true;
list<Node> x;
for (int i = 1; i <= n; i++) {
int a, b, e;
scanf("%d%d%d", &a, &b, &e);
fa[a] = a;
fa[b] = b;
if (e == 0)
x.push_back((Node){a, b, e});
if (e == 1)
x.push_front((Node){a, b, e});
}
for (auto _x : x) {
if (_x.e == 0) {
if (find_root(_x.i) == find_root(_x.j)) {
f ^= 1;
break;
}
}
if (_x.e == 1)
fa[find_root(_x.i)] = find_root(_x.j);
}
puts(f ? "YES" : "NO");
}
return 0;
}
这题用 map 做不了吗?