My friend the_hyp0cr1t3 and I came across this weird behaviour which we can't seem to explain.
The submissions 121761224 and 121761200 are identical, yet the former (submitted in C++17) gets accepted and the latter (submitted in C++14) gets WA on test 1.
After an hour of debugging, we managed to get it accepted in C++14 (121761314) with the following change in the code:
WA (C++14)
AC (C++14)
We would appreciate if someone could explain why something like a = b = c; and a = c; b = a; seem to produce different results.








If you have expression
a = bthen in C++17bwill be evaluated beforea, but in C++14 the order is not guaranteed. In your example it leads to the fact that firstst[node].lcis evaluated, which is a reference to something in vectorst. Thencreate(lc)is evaluated, size ofstincreases and because of how vector works, all elements are moved and reference tost[node].lcbecomes invalid, leading to UB.If you replace vector with deque, it works, since references to elements in deque are always valid: https://codeforces.me/contest/813/submission/121763992
That explains it very clearly. Thanks a lot!