Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <fstream>
  5.  
  6. int main()
  7. {
  8.  
  9.  
  10. std::ifstream in("input.txt");
  11. std::cin.rdbuf(in.rdbuf());
  12.  
  13. std::ofstream out("output.txt");
  14. std::cout.rdbuf(out.rdbuf());
  15.  
  16. int n;
  17. std::cin >> n;
  18. std::vector<std::vector<int>> graph(n, std::vector<int>(n));
  19.  
  20.  
  21. int flag;
  22.  
  23. for(int i = 0; i < n; ++i)
  24. {
  25. for(int j = 0; j < n; ++j)
  26. {
  27. std::cin >> flag;
  28. graph[i][j] = (flag);
  29. }
  30. }
  31.  
  32. int count_n = n;
  33.  
  34. std::queue<int> bfs;
  35. bfs.push(0);
  36.  
  37. std::vector<char> visit(n, 0);
  38.  
  39. while( !bfs.empty() )
  40. {
  41. int eax = bfs.front();
  42. bfs.pop();
  43. for(int i = 0; i < n; ++i)
  44. {
  45. if(graph[eax][i] && !visit[i])
  46. {
  47. --count_n;
  48. bfs.push(i);
  49. visit[i] = true;
  50. }
  51. }
  52.  
  53. }
  54.  
  55.  
  56. if ( count_n == 0)
  57. {
  58. std::cout << "Yes";
  59. }
  60. else
  61. {
  62. std::cout << "No";
  63. }
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement