Codeforces 500A - New Year Transportation Solution
Solution in C++:
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- #define mx 100090
- vector <int> vec[mx];
- bool visited[mx];
- void dfs(int source)
- {
- visited[source] = 1;
- for (int i = 0; i < vec[source].size(); i++)
- {
- int next = vec[source][i];
- if (visited[next] == 0)
- dfs(next);
- }
- }
- int main()
- {
- int n, t;
- cin >> n >> t;
- for (int i = 1; i < n; i++)
- {
- int a;
- cin >>a;
- vec[i].push_back(i+a);
- }
- dfs(1);
- if (visited[t] == 1)
- cout<<"YES"<<endl;
- else
- cout<<"NO"<<endl;
- }
No comments