#define OLC_PGE_APPLICATION #include "pixelGameEngine.h" #include "olcutils.h" using namespace olc; struct Room{ std::vectorconnections; std::mappaths; int flowValue=0; std::string name=""; friend std::ostream&operator<<(std::ostream&out,Room&rhs){ out<<"Valve "<rooms; int maxFlow=0; int iterations=0; int branchesRemaining=0; int findRoute(std::string start,std::string end,std::mapvisited,int dist){ visited[start]=true; int distance=INFINITY; Room r=rooms[start]; for (int i=0;ivisitedvalves,int flowRate,int minute,int flowTotal,std::string journey,std::string flowTotals){ //std::cout<<"Exploring "<maxFlow){ maxFlow=flowTotal; std::cout<<"New max found: "<::iterator it=rooms.begin();it!=rooms.end();++it){ if (visitedvalves.find(it->first)==visitedvalves.end()&&rooms[it->first].flowValue>0){ //We haven't tried going here yet. if (minute+rooms[currentRoom].paths[it->first]<30){ for (int i=0;ifirst];i++){ flowTotal+=flowRate; flowTotals+="->"+std::to_string(flowTotal); } explore(it->first,visitedvalves,flowRate,minute+rooms[currentRoom].paths[it->first],flowTotal,journey+"->"+it->first,flowTotals); flowTotal+=flowRate; flowTotals+="->"+std::to_string(flowTotal); explore(it->first,visitedvalves,flowRate+rooms[it->first].flowValue,minute+rooms[currentRoom].paths[it->first]+1,flowTotal,journey+"->"+it->first,flowTotals); flowTotal=previousFlowTotal; flowTotals=prevFlowTotal; } } } } int main() { std::ifstream file("input"); while (file.good()){ std::string line; std::getline(file,line); std::cout<0){ int flowRate=std::atoi(line.substr(line.find('=')+1,line.find(';')-line.find('=')-1).c_str()); std::cout<<"Flow Rate: "<::iterator it=rooms.begin();it!=rooms.end();++it){ for (std::map::iterator it2=rooms.begin();it2!=rooms.end();++it2){ if (it->first==it2->first){ rooms[it->first].paths[it2->first]=0; std::cout<first<<"->"<first<<": 0"<first].paths[it2->first]=findRoute(it->first,it2->first,{},0); std::cout<first<<"->"<first<<": "<first].paths[it2->first]<