Atcoder Beginner Contest 284 E - Count Simple Paths Solution



   Problem Link: https://atcoder.jp/contests/abc284/tasks/abc284_e

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int vis[200009];
  10. vector<int> adj[200009];
  11. int ans ;
  12. void dfs( int node ){
  13. if(ans==1e6)
  14. return;
  15. vis[node]=1;
  16. ans++;
  17. for ( auto v : adj[node]){
  18. if(!vis[v])
  19. dfs(v);
  20. }
  21. vis[node]=0;
  22. }
  23. int32_t main() {
  24. int n , e ;
  25. cin >> n >> e ;
  26. while ( e-- ){
  27. int u , v ;
  28. cin >> u >> v ;
  29. adj[u].push_back(v);
  30. adj[v].push_back(u);
  31. }
  32. ans = 0 ;
  33. dfs (1) ;
  34. cout<<ans<<endl;
  35. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.