HDU4694:Important Sisters(支配树)

博客探讨了在包含多个克隆体Misaka Mikoto(姐妹)的Misaka网络中,信息传递路径的问题。妹妹编号为N的个体作为消息源,其他所有妹妹直接或间接接收她的消息。重要姐妹是指在所有从N到其他妹妹的路径中都出现的妹妹。博客提供了多组测试案例,展示了如何计算每个妹妹的重要姐妹编号之和,并给出了基于支配树的解决方案和实现代码。
摘要由CSDN通过智能技术生成

Description
There are N clones of Misaka Mikoto (sisters) forming the Misaka network. Some pairs of sisters are connected so that one of them can pass message to the other one. The sister with serial number N is the source of all messages. All the other sisters get message directly or indirectly from her. There might be more than one path from sister #N to sister #I, but some sisters do appear in all of these paths. These sisters are called important sister of sister #K. What are the important sisters of each sister?
这里写图片描述

Input
There are multiple test cases. Process to the End of File.
The first line of each test case contains two integers: the number of sisters 1 ≤ N ≤ 50,000 and the number of connections 0 ≤ M ≤ 100,000. The following M lines are M connections 1 ≤ Ai, Bi ≤ N, indicating that Ai can pass message to Bi.

Output
For each test case, output the sum of the serial numbers of important sisters of each sister, separated with single space.

Sample Input
3 2
3 2
2 1
5 7
3 2
1 2
2 1
3 1
3 2
5 3
5 4

Sample Output
6 5 3
9 10 8 9 5

题意:
给一张n个点m条边的有向图,求n号节点到每个点的必经点的编号之和。

题解:
支配树。
求出每个点的支配点之后,从dfn编号小的递推至大的

ans[i]={
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值