The basic idea of the problem is that we should run a DFS on the direct recievers of a broadcasting cow to find the total messages possible through relay for said cow. We just need to make one optimization: make an adjacency list first for every cow (an 'adjacent' cow is one that can be directly broadcasted to from a certain cow) so we can save the time for scanning the list for direct recievers of the broadcasting cow. Finally, add on a visited vector to prevent infinity loops for every main cow and we have our answer.
The part that takes the most time is iterating over each cow's DFS. Here we have a time complexity of O(N^3), which passes only because n is so small (200 maximum). Since we run a DFS for each cow, we have to multiply the DFS's time complexity by N. The DFS's time complexity is N^2, because we would need to mark N nodes as visited and traverse (N - 1) * N or N^2 connections in worse case. Since N + N^2 simplifies to N^2, we multiply N^2 by N and get N^3.