links. Each pair [a, b] (with a < b) means that one of these two employees is above the other in the org chart, directly or several levels up. The chart is a tree with a single root: everyone except the root has exactly one direct manager, and a manager may have any number of reports.
The chart contains exactly the employees whose numbers appear in links. A pair is listed if and only if one of the two employees is above the other in the chain of command.
Two charts are different if at least one employee has a different direct manager in them. Return:
- 0 if no chart fits;
- 1 if exactly one chart fits;
- 2 if more than one chart fits.links=[[1, 4], [4, 7], [1, 7], [1, 9], [4, 8], [1, 8]] → 1
Exactly one chart fits: 1 is the root with reports 4 and 9, and 4 manages 7 and 8. Employee 1 is related to everyone, and 4 to everyone except 9.
links=[[2, 5], [3, 5], [2, 3]] → 2
All three are related, so they form a chain in any order, such as 2 → 3 → 5 or 5 → 2 → 3.
links=[[1, 2], [3, 4]] → 0
The root has to be related to everyone, and nobody here is.
len(links) ≤ 10⁵a < b ≤ 500 for every pair [a, b]links twicelinks=[[1, 4], [4, 7], [1, 7], [1, 9], [4, 8], [1, 8]]
1
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.