Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: vulkan
- * created: 03.08.2021 07:50:40 PM
- **/
- #include <bits/stdc++.h>
- using namespace std;
- void bfs(vector<vector<int>> &adj_list, int u, vector<bool> &visited) {
- int n = adj_list.size();
- queue<int> qu;
- qu.push(u);
- visited[u] = true;
- while (not qu.empty()) {
- int x = qu.front();
- qu.pop();
- for (int y : adj_list[x]) {
- if (not visited[y]) {
- visited[y] = true;
- qu.push(y);
- }
- }
- }
- }
- bool canVisitAllRooms(vector<vector<int>> &rooms) {
- int n = rooms.size();
- vector<bool> visited(n);
- bfs(rooms, 0, visited);
- return find(visited.begin(), visited.end(), false) == visited.end();
- }
- int main(int argc, char const *argv[]) {
- int n;
- cin >> n;
- vector<vector<int>> rooms(n);
- for (int i = 0; i <= n - 1; ++i) {
- int sz;
- cin >> sz;
- rooms[i] = vector<int>(sz);
- for (int j = 0; j <= sz - 1; ++j) {
- cin >> rooms[i][j];
- }
- }
- cout << canVisitAllRooms(rooms);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement