Codeforces 500A - New Year Transportation Solution





  

Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. #define mx 100090
    4. vector <int> vec[mx];
    5. bool visited[mx];
    6. void dfs(int source)
    7. {
    8. visited[source] = 1;
    9. for (int i = 0; i < vec[source].size(); i++)
    10. {
    11. int next = vec[source][i];
    12. if (visited[next] == 0)
    13. dfs(next);
    14. }
    15. }
    16. int main()
    17. {
    18. int n, t;
    19. cin >> n >> t;
    20. for (int i = 1; i < n; i++)
    21. {
    22. int a;
    23. cin >>a;
    24. vec[i].push_back(i+a);
    25. }
    26. dfs(1);
    27. if (visited[t] == 1)
    28. cout<<"YES"<<endl;
    29. else
    30. cout<<"NO"<<endl;
    31. }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

    Powered by Blogger.