fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int node,edge,zaoa_zay=0;
  4. vector<int>adj_list[20];
  5. map<char,int>mp;
  6. map<int,char>rev_mp;
  7. int vis[20];
  8. void DFS(int curr,int dst)
  9. {
  10. vis[curr]=1;
  11. if(curr==dst)
  12. {
  13. zaoa_zay=1;
  14. return ;
  15. }
  16. for(int i=0;i<adj_list[curr].size();i++)
  17. {
  18. int child=adj_list[curr][i];
  19. if(vis[child]==0 && zaoa_zay==0)
  20. {
  21. DFS(child,dst);
  22. }
  23. }
  24. return;
  25. }
  26. int main()
  27. {
  28. int id=0;
  29. int node,edge;
  30. cin>>node>>edge;
  31. for(int i=1;i<=edge;i++)
  32. {
  33. string e;
  34. cin>>e;
  35. if(mp.find(e[0])==mp.end())
  36. {
  37. mp[e[0]]=id;
  38. rev_mp[id]=e[0];
  39. id++;
  40. }
  41. if(mp.find(e[1])==mp.end())
  42. {
  43. mp[e[1]]=id;
  44. rev_mp[id]=e[1];
  45. id++;
  46. }
  47. adj_list[mp[e[0]]].push_back(mp[e[1]]);
  48. }
  49. char st,dst;
  50. cin>>st>>dst;
  51. for(int i=0;i<=node;i++)
  52. {
  53. vis[i]=0;
  54. }
  55. DFS(mp[st],mp[dst]);
  56. cout<<zaoa_zay<<endl;
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1