#C11327. Minimum Changes to Root Tree
Minimum Changes to Root Tree
Minimum Changes to Root Tree
You are given a tree with N nodes and M directed edges representing parent-child relationships. The tree is intended to be rooted at node 1. However, some edges might not currently originate from node 1.
For every edge \( (u,v) \), if \( u \neq 1 \), you need to perform a change so that the edge is reoriented with node 1 as the parent. In other words, you must count the number of edges where the parent is not \( 1 \).
Your task is to compute the minimum number of changes required in order for the tree to be properly rooted at node \( 1 \).
Note: The formula for the answer is given by \[ \text{answer} = \sum_{(u,v) \in E} I(u \neq 1), \] where \( I(statement) \) is \(1\) if the statement is true, and \(0\) otherwise.
inputFormat
The first line contains an integer \(N\) — the number of nodes in the tree.
The second line contains an integer \(M\) — the number of edges.
The following \(M\) lines each contain two integers \(u\) and \(v\) representing a directed edge from node \(u\) to node \(v\).
Input is given via standard input (stdin).
outputFormat
Output a single integer — the minimum number of changes required so that every edge originates from node \(1\).
Output must be written to standard output (stdout).
## sample4
3
1 2
1 3
3 4
1