The snippet vector<list>v(n); won’t compile - please format your code so that the forum software doesn’t mangle it!
How big is n, here? For many problems, they use 1 \le n \le 100000, and an adjacency matrix for n=100000 would be far too big to fit in memory.