Before reading, adapt the rerooting pattern to directed edges:
How do you compute the cost for node as root? (Hint: Count backward edges in DFS)
When moving root from u to v, how does the cost change? (Hint: Depends on whether edge is u→v or v→u)
Is this still rerooting? Try to write dfs1(u, parent) to count backward edges, and dfs2(u, parent, up_cost) to adjust cost when rerooting. Think about the edge direction. Spend minute thinking.