https://codeforces.net/contest/977/problem/D I am getting error in this problem. I have been trying to fix the error, but still getting "Memory limit exceeded on test 4" message. Please, help me to fix this problem. Here is my submission. https://codeforces.net/contest/977/submission/93731036 Thank you.
̶Y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶n̶'̶t̶ ̶u̶s̶e̶ ̶m̶a̶p̶ ̶h̶e̶r̶e̶ ̶b̶e̶c̶a̶u̶s̶e̶ ̶i̶n̶ ̶y̶o̶u̶r̶ ̶c̶o̶d̶e̶ ̶i̶t̶ ̶s̶t̶o̶r̶e̶s̶ ̶t̶o̶o̶ ̶m̶a̶n̶y̶ ̶e̶l̶e̶m̶e̶n̶t̶s̶.̶ ̶T̶h̶e̶ ̶m̶a̶x̶i̶m̶u̶m̶ ̶a̶l̶l̶o̶w̶e̶d̶ ̶n̶u̶m̶b̶e̶r̶ ̶o̶f̶ ̶i̶n̶d̶i̶c̶e̶s̶ ̶i̶s̶ ̶a̶b̶o̶u̶t̶ ̶1̶0̶^̶7̶,̶ ̶b̶u̶t̶ ̶y̶o̶u̶ ̶s̶t̶o̶r̶e̶ ̶1̶0̶^̶1̶8̶ ̶e̶l̶e̶m̶e̶n̶t̶s̶!̶ ̶I̶t̶'̶s̶ ̶i̶m̶p̶o̶s̶s̶i̶b̶l̶e̶ ̶f̶o̶r̶ ̶a̶ ̶s̶i̶n̶g̶l̶e̶ ̶P̶C̶ ̶h̶o̶l̶d̶ ̶s̶u̶c̶h̶ ̶a̶ ̶h̶u̶g̶e̶ ̶a̶m̶o̶u̶n̶t̶ ̶o̶f̶ ̶m̶e̶m̶o̶r̶y̶!̶
Sorry, I'm wrong. You should, in fact, use map, but the problem is with your dfs function. It seems that the map and the function are called too many times, which results in MLE.