Gym 101149L Right Build
In a MMORPG «Path of Exile» characters grow by acquiring talents for special talent points received in a game process. Talents can depend on others. A talent can be acquired only if a character has at least one of the talents it depends on. Acquiring one talent costs one talent point. At the beginning of the game a character has a single starting talent.
Schoolboy Vasiliy decided to record a video manual how to level-up a character in a proper way, following which makes defeating other players and NPCs very easy. He numbered all talents as integers from 0 to n, so that the starting talent is numbered as 0. Vasiliy thinks that the only right build is acquiring two different talents a and b as quickly as possible because these talents are imbalanced and much stronger than any others. Vasiliy is lost in thought what minimal number of talent points is sufficient to acquire these talents from the start of the game.
The first line contains four space-separated integers: n, m, a and b (2 ≤ n, m ≤ 2·105, 1 ≤ a, b ≤ n, a ≠ b) — the total number of talents, excluding the starting talent, the number of dependencies between talents, and the numbers of talents that must be acquired.
Each of the next m lines contains two space-separated integers: xj and yj (0 ≤ xj ≤ n, 1 ≤ yj ≤ n, xj ≠ yj), which means the talent yjdepends on the talent xj. It's guaranteed that it's possible to acquire all talents given the infinite number of talent points.
Output a single integer — the minimal number of talent points sufficient to acquire talents a and b.
【题意】
给出一个n个点m条边的有向连通图每次只有起点可以用终点才可以用,初始时0点可以用,问最少要用多少点才能用到a点和b点
【分析】
如果只是要用一个点a,那么求0->a的最短路即可,但是要用两个点就可能0->a和0->b都不是最短路,但是由于路径重叠很多点可以被用两次以节省用的点数,但是注意到两条路径只会是开始时重叠在一次,之后分开就再也不会相交,因为如果再次相交不如之前全部重叠更优,那么我们枚举这个叉点c,求出0->c,a->c,b->c的最短路来更新最优解即可
【代码】
__EOF__

本文链接:https://www.cnblogs.com/shenben/p/10420864.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
2017-02-22 [Sdoi2013]直径(树的直径)
2017-02-22 3123: [Sdoi2013]森林
2017-02-22 [Sdoi2013]随机数生成器(BSGS)
2017-02-22 [SDOI2011]计算器