File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 1- add_executable (daily_challenge p2021_3_18_WiggleSubsequence .cpp)
1+ add_executable (daily_challenge p2021_3_19_KeysAndRooms .cpp)
Original file line number Diff line number Diff line change 1+ //
2+ // Created by 10578 on 2021/3/19.
3+ //
4+
5+ #include " iostream"
6+ #include " fstream"
7+ #include " sstream"
8+ #include " string"
9+ #include " iterator"
10+ #include " algorithm"
11+ #include " vector"
12+ #include " unordered_set"
13+ #include " stack"
14+
15+ #define ALTER_IN (filename ) std::fstream fs (filename); std::cin.rdbuf(fs.rdbuf());
16+ #define BOOST_IO std::ios_base::sync_with_stdio (false ); std::cin.tie(nullptr ); std::cout.tie(nullptr );
17+
18+ __attribute__ ((constructor))
19+ void my_startup(){
20+ BOOST_IO;
21+ }
22+
23+ using namespace std ;
24+
25+ class Solution {
26+ public:
27+ bool canVisitAllRooms (vector<vector<int >>& rooms) {
28+ unordered_set<int > accessed;
29+
30+ stack<int > s;
31+ s.push (0 );
32+ accessed.insert (0 );
33+
34+ int current;
35+
36+ while (!s.empty ()) {
37+ current = s.top ();
38+ s.pop ();
39+
40+ for (auto &&x: rooms[current]) {
41+ if (!accessed.count (x)) {
42+ s.push (x);
43+ accessed.insert (x);
44+
45+ if (accessed.size () == rooms.size ()) {
46+ return true ;
47+ }
48+ }
49+ }
50+ }
51+
52+ return accessed.size () == rooms.size ();
53+ }
54+ };
55+
56+ int main (){
57+
58+
59+ return 0 ;
60+ }
You can’t perform that action at this time.
0 commit comments