Multiplayer Moo

Hello for this question, for the second part can someone elaborate on how “launching a floodfill” again after making the new graph finds the answer?

For each pair of cows x and y, we do flood fill only considering the edges that connect regions belonging to cow x to regions belonging to cow y.

But won’t that be too big as the IDs can go up to 10^6?

Well, for most pairs (x,y) there won’t be any edges connecting the regions, so just ignore those.