aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day16/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-17 11:41:36 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-17 11:41:36 +0800
commit8ed93bb340d781cbbc8f3c5b60a74bd3cbfbd438 (patch)
treea2c00174fa7d3c10856964302f90ff737854cb4e /src/2022/day16/aoc.cpp
parent8749bd4dfcfc86f2f99b5480ec0c289166da8c15 (diff)
downloadadvent-of-code-8ed93bb340d781cbbc8f3c5b60a74bd3cbfbd438.tar.gz
advent-of-code-8ed93bb340d781cbbc8f3c5b60a74bd3cbfbd438.zip
isolate effect
Diffstat (limited to 'src/2022/day16/aoc.cpp')
-rw-r--r--src/2022/day16/aoc.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/2022/day16/aoc.cpp b/src/2022/day16/aoc.cpp
index 17fd268..870ab9e 100644
--- a/src/2022/day16/aoc.cpp
+++ b/src/2022/day16/aoc.cpp
@@ -32,7 +32,7 @@ std::pair<int, size_t> get_opened(std::set<valve*>& opened) {
// return space;
// }
-void flow(int minute, valve* v, std::set<valve*>& opened, int total, int* maxtotal) {
+void flow(int minute, valve* v, std::set<valve*> opened, int total, int* maxtotal) {
auto p = get_opened(opened);
total += p.first;
// std::cout << indent(minute) << v->name;
@@ -47,7 +47,9 @@ void flow(int minute, valve* v, std::set<valve*>& opened, int total, int* maxtot
} else {
if (v->rate == 0 || v->open) {
for (auto& o : v->others) {
- flow(minute + 1, get(o), opened, total, maxtotal);
+ if (get(o)->rate == 0 || !get(o)->open) {
+ flow(minute + 1, get(o), opened, total, maxtotal);
+ }
}
} else { // v-rate > 0 && v->open == false
auto others = v->others;
@@ -59,8 +61,7 @@ void flow(int minute, valve* v, std::set<valve*>& opened, int total, int* maxtot
flow(minute + 2, get(o), opened, total, maxtotal);
}
else {
- auto os = opened;
- flow(minute + 1, get(o), os, total, maxtotal);
+ flow(minute + 1, get(o), opened, total, maxtotal);
}
}
}