Given a directed graph of domains, find the size of the largest set in which every domain can reach every other domain.
Medium6GraphDFSImplementationMathInterviewNo attempts yetTime limit2sMemory limit512 MBWe analyze how the domains on the Internet link to each other. A domain is the part of a URL that comes before the / character. twitter.com, aipo.computing.dcu.ie, and google.com are domains.
A domain d1 is connected to a domain d2 if there is a link from d1 to d2, or if d1 is connected to a domain d3 and d3 is connected to d2. Every domain is connected to itself.
The picture below shows a structure of five domains. Its links go from D1 to D2, D1 to D4, D2 to D3, D3 to D2, D3 to D4, D3 to D5, and D5 to D2.

We want the largest set of domains S in which every domain is connected to all the other domains of S. In the structure above the sets that meet this criterion are:
Given the links of the Internet, compute the size of the largest such set.
The first line contains an integer D, the number of domains. The names of the domains are the integers from 1 to D. (1≤D≤5000)
The second line contains an integer L, the number of links between domains. Each of the following L lines contains two integers. The first integer is the source of the link and the second is the destination. A link from A to B does not imply a link from B to A, and every domain is connected to itself without an explicit link. No link appears more than once. (0≤L≤D2)
Print the size of the largest set of domains that meets the criterion above. If two or more sets tie for the largest size, print that size once.