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 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.