Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(), (x).end()
- using namespace std;
- using ll = long long;
- vector<vector<int>> g;
- vector<bool> used;
- void Dfs(int from) {
- used[from] = true;
- for (int to : g[from]) {
- if (!used[to]) {
- Dfs(to);
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, t;
- cin >> n >> t;
- g.resize(n);
- used.assign(n, false);
- for (int i = 0; i < n - 1; i++) {
- int from = i;
- int a;
- cin >> a;
- int to = i + a;
- g[from].push_back(to);
- }
- Dfs(0);
- if (used[t - 1] == true) {
- cout << "YES\n";
- } else {
- cout << "NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement