resize is not what we want. You need to also clear all the adj[i]... an easy way to do it is the following after resizing:

fill(all(adj), vector<int>());

But please test if this works before submitting the change!