#line 1 "274.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/274" #line 1 "/home/mmrz/competitive_programming/cp_templates/template/template.hpp" # include using namespace std; using ll = long long; using ull = unsigned long long; const double pi = acos(-1); templateconstexpr T inf() { return ::std::numeric_limits::max(); } templateconstexpr T hinf() { return inf() / 2; } template T_char TL(T_char cX) { return tolower(cX); } template T_char TU(T_char cX) { return toupper(cX); } template bool chmin(T& a,T b) { if(a > b){a = b; return true;} return false; } template bool chmax(T& a,T b) { if(a < b){a = b; return true;} return false; } int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; } int d_sum(ll n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; } int d_cnt(ll n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; } ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a%b); }; ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g*b; }; ll MOD(ll x, ll m){return (x%m+m)%m; } ll FLOOR(ll x, ll m) {ll r = (x%m+m)%m; return (x-r)/m; } template using dijk = priority_queue, greater>; # define all(qpqpq) (qpqpq).begin(),(qpqpq).end() # define UNIQUE(wpwpw) (wpwpw).erase(unique(all((wpwpw))),(wpwpw).end()) # define LOWER(epepe) transform(all((epepe)),(epepe).begin(),TL) # define UPPER(rprpr) transform(all((rprpr)),(rprpr).begin(),TU) # define rep(i,upupu) for(ll i = 0, i##_len = (upupu);(i) < (i##_len);(i)++) # define reps(i,opopo) for(ll i = 1, i##_len = (opopo);(i) <= (i##_len);(i)++) # define len(x) ((ll)(x).size()) # define bit(n) (1LL << (n)) # define pb push_back # define exists(c, e) ((c).find(e) != (c).end()) struct INIT{ INIT(){ std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(20); } }INIT; namespace mmrz { void solve(); } int main(){ mmrz::solve(); } #line 1 "/home/mmrz/competitive_programming/cp_templates/graph/two_sat.hpp" #line 1 "/home/mmrz/competitive_programming/cp_templates/graph/strongly_connected_components.hpp" struct scc_graph { vector> g; vector> rg; vector used; vector cmp; vector vs; int n; int k; scc_graph(int _n) : n(_n), k(0) { g.resize(n); rg.resize(n); used.resize(n); cmp.resize(n); } void add_edge(int a, int b) { g[a].push_back(b); rg[b].push_back(a); } void dfs(int v){ used[v] = true; for(auto to : g[v]){ if(not used[to])dfs(to); } vs.pb(v); } void rdfs(int v, int col){ used[v] = true; cmp[v] = col; for(auto to : rg[v]){ if(not used[to])rdfs(to, col); } } vector> scc() { for(int i = 0;i < n;i++){ if(not used[i])dfs(i); } for(int i = 0;i < n;i++){ used[i] = false; } for(auto i = vs.rbegin();i != vs.rend();i++){ if(not used[*i])rdfs(*i, k++); } vector> ret(k); for(int i = 0;i < n;i++){ ret[cmp[i]].push_back(i); } return ret; } }; #line 3 "/home/mmrz/competitive_programming/cp_templates/graph/two_sat.hpp" struct two_sat { int n; scc_graph g; two_sat(int _n) : n(_n), g(scc_graph(2*n)) {} // (i = f1) || (j = f2) void add_clause(int i, bool f1, int j, bool f2){ g.add_edge((i << 1) ^ !f1, (j << 1) ^ f2); g.add_edge((j << 1) ^ !f2, (i << 1) ^ f1); } // (i = f1) -> (j = f2) <=> (1 = !f1) || (j = f2) void add_if(int i, bool f1, int j, bool f2){ add_clause(i, !f1, j, f2); } // i void set_true(int i){ add_clause(i, true, i, true); } // !i void set_false(int i){ add_clause(i, false, i, false); } vector solve(){ vector> scc = g.scc(); vector c(2*n); for(int i = 0;i < (int)scc.size();i++){ for(auto v : scc[i]){ c[v] = i; } } vector res(n); for(int i = 0;i < n;i++){ if(c[i << 1] == c[i << 1 | 1])return vector(); res[i] = (c[i << 1] < c[i << 1 | 1]); } return res; } }; #line 5 "274.test.cpp" void mmrz::solve(){ int n, m; cin >> n >> m; two_sat ts(n); vector l(n), r(n); rep(i, n){ cin >> l[i] >> r[i]; r[i]++; } auto is_overlap = [&](int l1, int r1, int l2, int r2) -> bool { return not (r1 <= l2 || r2 <= l1); }; rep(i, n){ rep(j, n){ if(i == j)continue; bool f1 = is_overlap(l[i], r[i], l[j], r[j]); bool f2 = is_overlap(l[i], r[i], m-r[j], m-l[j]); if(not f1 && not f2)continue; if(f1 && f2){ cout << "NO" << endl; return; } if(f1){ ts.add_if(i, true, j, false); ts.add_if(i, false, j, true); } if(f2){ ts.add_if(i, true, j, true); ts.add_if(i, false, j, false); } } } auto ret = ts.solve(); cout << (len(ret) ? "YES" : "NO") << endl; }