MediumRating 1861
1993. Operations on Tree
arrayhash-tabletreedepth-first-searchbreadth-first-searchdesign
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Constructor: a. Build children list from parent array b. Initialize lockedBy array with -1 (unlocked) 2. lock(num, user): a. If lockedBy[num] != -1: return false b. Set lockedBy[num] = user, return true 3. unlock(num, user): a. If lockedBy[num] != user: return false b. Set lockedBy[num] = -1, return true 4. upgrade(num, user): a. If lockedBy[num] != -1: return false b. Walk up ancestors; if any locked: return false c. DFS descendants: unlock all locked ones, track if any found d. If no locked descendant found: return false e. Set lockedBy[num] = user, return true