Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <fstream>
- int main()
- {
- std::ifstream in("input.txt");
- std::cin.rdbuf(in.rdbuf());
- std::ofstream out("output.txt");
- std::cout.rdbuf(out.rdbuf());
- int n;
- std::cin >> n;
- std::vector<std::vector<int>> graph(n, std::vector<int>(n));
- int flag;
- for(int i = 0; i < n; ++i)
- {
- for(int j = 0; j < n; ++j)
- {
- std::cin >> flag;
- graph[i][j] = (flag);
- }
- }
- int count_n = n;
- std::queue<int> bfs;
- bfs.push(0);
- std::vector<char> visit(n, 0);
- while( !bfs.empty() )
- {
- int eax = bfs.front();
- bfs.pop();
- for(int i = 0; i < n; ++i)
- {
- if(graph[eax][i] && !visit[i])
- {
- --count_n;
- bfs.push(i);
- visit[i] = true;
- }
- }
- }
- if ( count_n == 0)
- {
- std::cout << "Yes";
- }
- else
- {
- std::cout << "No";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement