#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, static_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, dynamic_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const atcoder::segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const atcoder::lazy_segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} // Weighted Union Find // O(alpha(N)) // thanks for "https://ei1333.github.io/luzhiled/snippets/structure/union-find.html" template struct WeightedUnionFind { vector data; vector ws; WeightedUnionFind() {} WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {} int root(int k){ if(data[k] < 0) return k; auto par = root(data[k]); ws[k] += ws[data[k]]; return data[k] = par; } T weight(int t) { root(t); return ws[t]; } bool same(int x, int y){ x = root(x), y = root(y); if(x == y) return true; else return false; } bool merge(int x, int y, T w) { w += weight(x); w -= weight(y); x = root(x), y = root(y); if(x == y) return false; if(data[x] > data[y]) { swap(x, y); w *= -1; } data[x] += data[y]; data[y] = x; ws[y] = w; return true; } T dif(int x, int y) { return weight(y) - weight(x); } }; int main(){ int n; cin >> n; WeightedUnionFind uf(n); map, vector>> ma; auto f = [&](int i, int pari, pair p){ for(auto [j, parj] : ma[p]){ int w = pari ^ parj; if(uf.same(i, j)){ int diff = uf.dif(i, j) + w; if((diff % 2 + 2) % 2){} else return false; }else{ uf.merge(i, j, w + 1); } } return true; }; rep(i, n){ int a, b, c; cin >> a >> b >> c; if(!f(i, 0, make_pair(a, b))){cout << "NO\n"; return 0;} if(!f(i, 0, make_pair(b, c))){cout << "NO\n"; return 0;} if(!f(i, 1, make_pair(a, c))){cout << "NO\n"; return 0;} ma[make_pair(a, b)].emplace_back(i, 0); ma[make_pair(b, c)].emplace_back(i, 0); ma[make_pair(a, c)].emplace_back(i, 1); } cout << "YES\n"; return 0; }