#include using namespace std; #pragma region atcoder #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; } } }; 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}}); } 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 #include #include namespace atcoder { 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 using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007; #pragma endregion #pragma region macros using ll = long long; using PII = pair; using PLL = pair; template using V = vector; template using VV = V>; #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0;i(a);) #define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #pragma endregion #pragma region debug for var, v, vv #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template void view(T e){std::cerr << e << std::endl;} template void view(const std::vector& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template void view(const std::vector >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} #pragma endregion #pragma region int128 std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } #pragma endregion const ll mod = 1000000007; const int inf = 1001001001; const ll INF = 1001001001001001001ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; templatebool chmax(T &a, const K b) { if (abool chmin(T &a, const K b) { if (b0&&a%b); } // 20 / 3 == 7 ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7 ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} /*---------------------------------------------------------------------------------------------------------------------------------*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int n, m; cin >> n >> m; V l(n), r(n); rep(i,n) cin >> l[i] >> r[i]; atcoder::two_sat st(n); rep(i,n){ rep(j,i+1,n){ if(l[i] <= l[j] && l[j] <= r[i] || l[i] <= r[j] && r[j] <= r[i]){ st.add_clause(i, false, j, false); } if(l[i] <= m - r[j] - 1 && m - r[j] - 1 <= r[i] || l[i] <= m - l[j] - 1 && m - l[j] - 1 <= r[i]){ st.add_clause(i, false, j, true); } if(m - r[i] - 1 <= l[j] && l[j] <= m - l[i] - 1 || m - r[i] - 1 <= r[j] && r[j] <= m - l[i] - 1){ st.add_clause(i, true, j, false); } if(m - r[i] - 1 <= m - r[j] - 1 && m - r[j] - 1 <= m - l[i] - 1 || m - r[i] - 1 <= m - l[j] - 1 && m - l[j] - 1 <= m - l[i] - 1){ st.add_clause(i, true, j, true); } } } if(st.satisfiable()) cout << "YES" << endl; else cout << "NO" << endl; } /* * review you code when you get WA (typo? index?) * int overflow, array bounds * special cases (n=1?) */