Comments

Really Cool. Thanks for looking at the code!

I'll keep that in mind from now. Thanks a ton!

oh is it so? It's so frustating and unfortunate that python is slow. Thanks a lot!

Oh, graph is a dictionary here (HashMap), constant lookup.

Sir, it's not N^2. Could you please see my above reply to bleh0.5

Actually, the set size will never grow more than 3 elements (the inner loop). It looks N^2 but it's not

It's the submission for C

Could anyone please tell me why this was giving TLE? https://codeforces.me/contest/1325/submission/73271304

Thanks!