#include #include #include #include #include #include struct Room{ std::vectorconnections; std::mappaths; int flowValue=0; std::string name=""; friend std::ostream&operator<<(std::ostream&out,Room&rhs){ out<<"Valve "<rooms; std::vectortargetRooms; int maxFlow=0; int iterations=0; int branchesRemaining=0; void printArr(){ int minutesRemaining1=26; int minutesRemaining2=26; std::string currentPos="AA"; std::string path1="AA"; std::string currentPos2="AA"; std::string path2="AA"; std::vector movePlan1; std::vector movePlan2; int moveAmt1=0; //How many steps left to move. int moveAmt2=0; //How many steps left to move. int currentMarker1=0; int currentMarker2=0; int flowRate=0; int flowTotal=0; for (int i=0;i0){ std::cout<<" Moving to "<0){ std::cout<<" Moving to "<maxFlow){ maxFlow=flowTotal; std::cout<<"New max flow is "< arr){ for (int i=0;i&arr,int size){ if (size==1){ printArr(); return; } for (int i=0;ivisited,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: "<0){ targetRooms.push_back(valveName); } while (marker!=std::string::npos){ std::string roomName=line.substr(marker-2,2); std::cout<<"Connection w/"<::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]<