Binlogs
27 subscribers
18 photos
125 links
Download Telegram
how to know if a node is an ancestor of another node in a tree?

first let's have a global variable that tracks time, which starts from zero.
when traversing the tree using dfs, track the "in" and "out" time of each node.

- "in" time = is the time at which the recursive dfs function is on that node.
- "out" time = is the time after the dfs function traversed every child and grand children of the current node.

to show it in code.

def dfs(node):
# "in" time is here

for child in graph[node]:
dfs(child)

# "out" time is here


let "x" be a node and "y" be another that node. then we can check "x" is an ancestor of "y",
if in(x) < in(y) < out(x).


#lessons
Forwarded from DoughNut 🍩
Looking for those cool isometric shapes on websites? Here's a tool that has a bunch of them

https://www.isocons.app/

#Frontend
I found this site [yosupo judge], which is kind of similar to [cses fi].

I have solved this question there: [Deque]
🔥2
ai summary