There exists an undirected tree with n nodes numbered 0 to n - 1.
You are given a 2D integer array edges of length n - 1, where edges[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the tree.
Initially, all nodes are unmarked. For each node i:
If i is odd, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 1.
If i is even, the node will get marked at time x if there is at least one node adjacent to it which was marked at time x - 2.
Return an array times where times[i] is the time when all nodes get marked in the tree, if you mark node i at time t = 0.
Note that the answer for each times[i] is independent , i.e. when you mark node i all other nodes are unmarked.
Input: edges =[[0,1],[0,2]]Output: [2,4,3]Explanation:

* For `i = 0`:* Node 1is marked at `t = 1`, and Node 2 at `t = 2`.* For `i = 1`:* Node 0is marked at `t = 2`, and Node 2 at `t = 4`.* For `i = 2`:* Node 0is marked at `t = 2`, and Node 1 at `t = 3`.
For each node as the root, perform BFS, propagating marks according to the node’s parity. Use a queue and track the earliest time each node can be marked.
from collections import deque, defaultdict
from typing import List
classSolution:
defminimumTimeToMarkAllNodes(self, n: int, edges: List[List[int]]) -> List[int]:
g = [[] for _ in range(n)]
for u, v in edges:
g[u].append(v)
g[v].append(u)
res = [0] * n
for start in range(n):
time = [float('inf')] * n
time[start] =0 q = deque([start])
while q:
u = q.popleft()
for v in g[u]:
d =1if u %2else2if time[v] > time[u] + d:
time[v] = time[u] + d
q.append(v)
res[start] = max(time)
return res