#C1267. Maximum Unique Cards
Maximum Unique Cards
Maximum Unique Cards
You are given n different card types numbered from 0 to n-1 and m possible one-way trades between them. Each trade is represented as a directed edge from card type s to card type t.
Starting with card type 0, your task is to determine the maximum number of distinct card types you can collect by performing these trades. The trading process follows the directed graph of possible trades.
The relationship between the cards and trades can be formulated as follows:
\(\text{Let } G = (V, E)\) where \(V = \{0, 1, \ldots, n-1\}\) and \(E\) represents the directed trades. Find the number of nodes reachable from node 0 using a breadth-first search (BFS) or depth-first search (DFS).
inputFormat
The first line contains two integers n and m (\(1 \leq n \leq 10^5\), \(0 \leq m \leq 10^5\)) representing the number of card types and the number of trades respectively.
The next m lines each contain two integers s and t (\(0 \leq s, t < n\)) indicating a one-way trade from card type s to card type t.
outputFormat
Output a single integer representing the maximum number of different card types that can be collected starting from card type 0.
## sample4 3
0 1
1 2
1 3
4