题意:https://www.luogu.com.cn/problem/AT_abc238_e
思路:对于每个已知区间l,r,我们建一个l-1到r的边,然后对于答案我们看是否0可以到n就行。
/*keep on going and never give up*/
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define lowbit(x) x&(-x)
#define endl '\n'
#define wk is zqx ta die
vector<int> vc[200005];
int vis[200005];
int n, q;
int ok = 0;
void dfs(int x) {
if (x == n) {
ok = 1;
return ;
}
for (auto k : vc[x]) {
if (vis[k] == 0) {
vis[k] = 1;
dfs(k);
}
}
}
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
while (q--) {
int l, r;
cin >> l >> r;
vc[l - 1].push_back(r);
vc[r].push_back(l - 1);
}
vis[0] = 1;
dfs(0);
if (ok) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}