For this Question: You have N light bulbs, however they are currently jumbled up in wires. When you start unravelling the bulbs, you observe that the situation can be described by a directed acyclic graph connecting the bulbs to each other.

Formally, you are given a directed graph consisting of N nodes (numbered 1 to N) and M edges such that it contains no cycles. A sequence of vertices (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) is called a path if there exists an edge from v<sub>i</sub> to v<sub>i+1</sub> for every i such that 1 ≤ i ≤ k-1. A path (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) in the graph is called maximal, if for any vertex v, the sequence (v, v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>) or (v<sub>1</sub>, v<sub>2</sub>, ... v<sub>k</sub>, v) do not represent paths in the graph. 

Find the number of maximal paths in the graph.The first line contains two integers N and M.
The next M lines each contain two integers u and v – representing an edge from vertex u to vertex v.

<b> Constraints: </b>
1 ≤ N ≤ 10<sup>5</sup>
0 ≤ M ≤ 2×10<sup>5</sup>
1 ≤ u, v ≤ N
The graph does not contain any self-loops or multiple edges.Print a single integer – the number of maximal paths.Sample Input 1:
3 1
1 2

Sample Output 1:
2

Sample Explanation 1:
The two maximal paths are (1, 2) and (3).

Sample Input 2:
3 3
1 2
2 3
1 3

Sample Output 2:
2

Sample Explanation 1:
The two maximal paths are (1, 2, 3) and (1, 3).

Sample Input 3:
3 2
1 3
3 2

Sample Output 3:
1

Sample Explanation 3:
The only maximal path is (1, 3, 2)., I have written this Solution Code: import java.io.*;
import java.util.*;

public class Main {
	public static void solve(FastIO io) {
		final int N = io.nextInt();
		final int M = io.nextInt();

		Node[] nodes = new Node[N + 1];
		for (int i = 1; i <= N; ++i) {
			nodes[i] = new Node(i);
		}

		for (int i = 0; i < M; ++i) {
			final int U = io.nextInt();
			final int V = io.nextInt();

			nodes[U].next.add(nodes[V]);
			++nodes[V].indegree;
		}

		long total = 0;
		long[] ans = new long[N + 1];
		Arrays.fill(ans, -1);
		for (int i = 1; i <= N; ++i) {
			if (nodes[i].indegree == 0) {
				total += countMaximal(nodes[i], ans);
			}
		}
		io.println(total);
	}

	private static long countMaximal(Node u, long[] ans) {
		if (ans[u.id] < 0) {
			if (u.next.isEmpty()) {
				ans[u.id] = 1;
			} else {
				long got = 0;
				for (Node v : u.next) {
					got += countMaximal(v, ans);
				}
				ans[u.id] = got;
			}
		}
		return ans[u.id];
	}

	private static class Node {
		public int id;
		public List<Node> next = new LinkedList<>();
		public int indegree;

		public Node(int id) {
			this.id = id;
		}
	}

	public static class FastIO {
		private InputStream reader;
		private PrintWriter writer;

		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastIO(InputStream r, OutputStream w) {
			reader = r;
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = reader.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}


		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		public int[] nextIntArray(int n, int off) {
			int[] arr = new int[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		public long[] nextLongArray(int n, int off) {
			long[] arr = new long[n + off];
			for (int i = 0; i < n; i++) {
				arr[i + off] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void printArray(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printArray(long[] arr) {
			for (int i = 0; i < arr.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(arr[i]);
			}
		}

		public void printlnArray(int[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printlnArray(long[] arr) {
			printArray(arr);
			writer.println();
		}

		public void printf(String format, Object... args) {
			print(String.format(format, args));
		}

		public void flush() {
			writer.flush();
		}
	}

	private static class Solution implements Runnable {
		@Override
		public void run() {
			FastIO io = new FastIO(System.in, System.out);
			solve(io);
			io.flush();
		}
	}

	public static void main(String[] args) throws InterruptedException {
		Thread t = new Thread(null, new Solution(), "Solution", 1 << 30);
		t.start();
		t.join();
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?