I was trying to solve problem D from this competition (it's not really important to read the task) and I noted that these two codes that make the same thing are slightly different in time of execution:
map < string, vector <string> > G;
// Version 1
bool dfs(string s, string t) {
if( s == t ) return true;
for(int i = 0; i < int(G[s].size()); i++) {
if( dfs( G[s][i], t ) ) return true;
}
return false;
}
// Version 2
bool dfs(string s, string t) {
if( s == t ) return true;
for(auto r: G[s]) {
if( dfs( r, t ) ) return true;
}
return false;
}
In particular Version 1 gets TLE in evaluation, instead Version 2 pass without any problem. According to this question it's strange that Version 1 is slower, and testing on my PC with the largest testcase I get same time of execution... Can you help me?