Unreachable Nodes in a DAG
You are given a directed acyclic graph (DAG) with $N$ nodes and $M$ edges. Some nodes might have no incoming edges. We define 'source nodes' as nodes with an in-degree of 0. All nodes reachable from any source node are considered 'reachable'. Your task is to count the number of nodes that are not reachable from any source node.
Input
The first line contains two integers $N$ and $M$, the number of nodes and edges. The following $M$ lines each contain two integers $u$ and $v$, representing a directed edge from node $u$ to node $v$. Nodes are numbered from 1 to $N$.
Output
Print a single integer: the count of unreachable nodes.
Constraints
1 \le N \le 200000, 0 \le M \le 200000. The graph is guaranteed to be a Directed Acyclic Graph (DAG).
Example 1
5 3 1 2 1 3 2 4
0
Nodes 1, 2, 3, 4 are reachable from source node 1. Node 5 is unreachable.
Example 2
4 4 1 2 1 3 2 4 3 4
0
Nodes 1, 2, 3, 4 are all reachable from source node 1.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 3 1 2 1 3 2 4
4 4 1 2 1 3 2 4 3 4