This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5e5;
int l[mxn], r[mxn], s[mxn];
int n;
void subtask3(){
	int deg[2*n];
	memset(deg, 0, sizeof(deg));
	
	fr(i, 0, n){
		deg[l[i]]++;
		deg[r[i]+n]++;
	}
	fr(i, 0, 2*n){
		if(deg[i] % 2){
			cout<<"NO"<<endl;
			return;
		}
	}
	cout<<"YES"<<endl;
}
void solve(){
	cin >> n;
	bool sub3 = true;
	fr(i, 0, n){
		cin >> l[i] >> r[i] >> s[i];
		--l[i], --r[i];
		if(s[i] != 1) sub3 = false;
	}
	subtask3();
	
	
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	
}
Compilation message (stderr)
tug.cpp: In function 'void solve()':
tug.cpp:47:7: warning: variable 'sub3' set but not used [-Wunused-but-set-variable]
  bool sub3 = true;
       ^~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |