HardRating 3018
1719. Number Of Ways To Reconstruct A Tree
arrayhash-tabletreegraphsimulation
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Build adjacency sets from pairs 2. Sort nodes by degree descending 3. If root (highest degree) does not have degree n-1, return 0 4. For each node v (in sorted order): a. Find parent = neighbor with smallest degree >= deg(v) b. If no parent found and v is not root, return 0 c. Check all neighbors of v (except parent) are also neighbors of parent d. If check fails, return 0 e. If parent has same degree as v, mark multipleWays = true 5. Return 2 if multipleWays, else 1