Https://ide.codingblocks.com/s/246071


Please check

apply this algo
The problem is simple implementation of DFS while maintaining a count of children of the vertices visited. Let u be a vertex and v be its child. Then, check if children[v]>children[u].This way, check for each vertex while traversing the graph in DFS. One important thing to note that actually there are many trees in the input(a graph with no cycles and self loops is a tree). That means , you have to apply DFS for each of these trees.

I made some changes but still wrong answer

first of all add all vertex 1 to N


you can see this .

Main function should look like this
public static void main(String[] args) {
Main graph = new Main();
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int m = scn.nextInt();
int v = n;
int p = 1;
while (v-- > 0) {
graph.addVertex§;
p++;
}
while (m-- > 0) {
int x = scn.nextInt();
int y = scn.nextInt();
// graph.addVertex(x);
// graph.addVertex(y);
graph.addPC(x, y);
graph.addEdges(x, y);
}
graph.dft();
System.out.println(count);
}
Another approach here:
look at this one

Great i’ll go through ur code bt can u pls see why my code is not working… This is the final draft

Great i’ll go through ur code bt can u pls see why my code is not working… This is the final draft https://ide.codingblocks.com/s/247600

Your code has infinite loop. debug your code