#include using namespace std; typedef long long ll; typedef long double ld; typedef pair pll; typedef pair pli; typedef pair pii; typedef pair pld; typedef pair ppiii; typedef pair ppiil; typedef pair pplll; typedef pair pplii; typedef vector> vvl; typedef vector> vvi; typedef vector> vvpll; #define rep(i, a, b) for (ll i=(a); i<(b); i++) #define rrep(i, a, b) for (ll i=(a); i>(b); i--) #define pb push_back #define tostr to_string #define mkp make_pair #define list2d(name, N, M, type, init) vector> name(N, vector(M, init)) const ll INF = LONG_LONG_MAX; const ll MOD = 998244353; void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; } void print(double out) { cout << fixed << setprecision(15) << out << '\n'; } template void print(T out) { cout << out << '\n'; } template void print(pair out) { cout << out.first << ' ' << out.second << '\n'; } template void print(vector A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } } template void print(set S) { vector A(S.begin(), S.end()); print(A); } template inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; } template inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; } ll sum(vector A) { ll res = 0; for (ll a: A) res += a; return res; } ll max(vector A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; } ll min(vector A) { ll res = INF; for (ll a: A) chmin(res, a); return res; } ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; } // 数字なら'0'、アルファベットなら'a'みたいに使い分ける // int toint(char c) { return c - '0'; } // char tochar(int i) { return '0' + i; } inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; } inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } } inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } } pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; } int popcount(ll S) { return __builtin_popcountll(S); } ll gcd(ll a, ll b) { return __gcd(a, b); } #ifndef ATCODER_INTERNAL_SCC_HPP #define ATCODER_INTERNAL_SCC_HPP 1 #include #include #include namespace atcoder { namespace internal { template struct csr { std::vector start; std::vector elist; csr(int n, const std::vector>& edges) : start(n + 1), elist(edges.size()) { for (auto e : edges) { start[e.first + 1]++; } for (int i = 1; i <= n; i++) { start[i] += start[i - 1]; } auto counter = start; for (auto e : edges) { elist[counter[e.first]++] = e.second; } } }; // Reference: // R. Tarjan, // Depth-First Search and Linear Graph Algorithms struct scc_graph { public: scc_graph(int n) : _n(n) {} int num_vertices() { return _n; } void add_edge(int from, int to) { edges.push_back({from, {to}}); } // @return pair of (# of scc, scc id) std::pair> scc_ids() { auto g = csr(_n, edges); int now_ord = 0, group_num = 0; std::vector visited, low(_n), ord(_n, -1), ids(_n); visited.reserve(_n); auto dfs = [&](auto self, int v) -> void { low[v] = ord[v] = now_ord++; visited.push_back(v); for (int i = g.start[v]; i < g.start[v + 1]; i++) { auto to = g.elist[i].to; if (ord[to] == -1) { self(self, to); low[v] = std::min(low[v], low[to]); } else { low[v] = std::min(low[v], ord[to]); } } if (low[v] == ord[v]) { while (true) { int u = visited.back(); visited.pop_back(); ord[u] = _n; ids[u] = group_num; if (u == v) break; } group_num++; } }; for (int i = 0; i < _n; i++) { if (ord[i] == -1) dfs(dfs, i); } for (auto& x : ids) { x = group_num - 1 - x; } return {group_num, ids}; } std::vector> scc() { auto ids = scc_ids(); int group_num = ids.first; std::vector counts(group_num); for (auto x : ids.second) counts[x]++; std::vector> groups(ids.first); for (int i = 0; i < group_num; i++) { groups[i].reserve(counts[i]); } for (int i = 0; i < _n; i++) { groups[ids.second[i]].push_back(i); } return groups; } private: int _n; struct edge { int to; }; std::vector> edges; }; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_SCC_HPP #ifndef ATCODER_TWOSAT_HPP #define ATCODER_TWOSAT_HPP 1 #include #include namespace atcoder { // Reference: // B. Aspvall, M. Plass, and R. Tarjan, // A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean // Formulas struct two_sat { public: two_sat() : _n(0), scc(0) {} two_sat(int n) : _n(n), _answer(n), scc(2 * n) {} void add_clause(int i, bool f, int j, bool g) { assert(0 <= i && i < _n); assert(0 <= j && j < _n); scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0)); scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0)); } bool satisfiable() { auto id = scc.scc_ids().second; for (int i = 0; i < _n; i++) { if (id[2 * i] == id[2 * i + 1]) return false; _answer[i] = id[2 * i] < id[2 * i + 1]; } return true; } std::vector answer() { return _answer; } private: int _n; std::vector _answer; internal::scc_graph scc; }; } // namespace atcoder #endif // ATCODER_TWOSAT_HPP using namespace atcoder; ll N, M; vector L, R; bool check(ll l1, ll r1, ll l2, ll r2) { return (l1 >= r2 || l2 >= r1); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; L.resize(N); R.resize(N); rep(i, 0, N) { cin >> L[i] >> R[i]; R[i]++; } // ts[i] := i行目を反転させるか two_sat ts(N); rep(i, 0, N) { rep(j, i+1, N) { // 0, 0 if (!check(L[i], R[i], L[j], R[j])) { // a & bがNGなら、!a | !bを条件に追加する ts.add_clause(i, 1, j, 1); } // 1, 0 if (!check(M-R[i], M-L[i], L[j], R[j])) { ts.add_clause(i, 0, j, 1); } // 0, 1 if (!check(L[i], R[i], M-R[j], M-L[j])) { ts.add_clause(i, 1, j, 0); } // 1, 1 if (!check(M-R[i], M-L[i], M-R[j], M-L[j])) { ts.add_clause(i, 0, j, 0); } } } if (ts.satisfiable()) { print("YES"); } else { print("NO"); } return 0; }