← 返回 bloomberg 的题目列表Find the Root Cause Node from Parent-to-Children Logs
类型:online_judge
You are given logs describing a parent-to-children relationship that forms a tree (or a forest). Each record has the form:
[node, [child1, child2, ...]], meaning directed edges node -> child for each listed child.
Find the root node: the node with in-degree 0 (it never appears as any other node’s child).
Input (stdin)
The first line contains an integer n, the number of records. Then n lines follow, each formatted as:
node k child1 child2 ... childk
where k is the number of children.
Output (stdout)
Print the root node identifier.
Constraints
1 <= n <= 2*10^5
Total number of nodes V <= 2*10^5
Node identifiers are whitespace-free strings
Assume there is exactly one root (you may ignore invalid inputs)
Sample Tests
See the Chinese section.
Example
Input
3
A 2 B C
B 1 D
C 0
Output
A