题目链接: https://nanti.jisuanke.com/t/39280
There are n n n planets in the MOT galaxy, and each planet has a unique number from 1 ∼ n 1∼n 1∼n. Each planet is connected to other planets through some transmission channels. There are m m m transmission channels in the galaxy. Each transmission channel connects two different planets, and each transmission channel has a length. The residents of the galaxy complete the interplanetary voyage by spaceship. Each spaceship has a level. The spacecraft can be upgraded several times. It can only be upgraded 1 1 1 level each time, and the cost is c c c. Each upgrade will increase the transmission distance by d d d and the number of transmissions channels by e e e to the spacecraft. The spacecraft can only pass through channels that are shorter than or equal to its transmission distance. If the number of transmissions is exhausted, the spacecraft can no longer be used. Alice initially has a 0 0 0-level spacecraft with transmission distance of 0 0 0 and transmission number of 0 0 0. Alice wants to know how much it costs at least, in order to transfer from planet 1 1 1 to planet n n n.
Each test file contains a single test case. In each test file: The first line contains n , m , n, m, n,m, indicating the number of plants and the number of transmission channels. The second line contains c , d , e , c, d, e, c,d,e, representing the cost, the increased transmission distance, and the increased number of transmissions channels of each upgrade, respectively. Next m m m lines, each line contains u , v , w , u,v,w, u,v,w, meaning that there is a transmission channel between u u u and v v v with a length of w w w. ( 2 ≤ n ≤ 1 0 5 , n − 1 ≤ m ≤ 1 0 5 , 1 ≤ u , v ≤ n , 1 ≤ c , d , e , w ≤ 1 0 5 ) (2≤n≤10^5, n-1≤m≤10^5,1≤u,v≤n ,1≤c,d,e,w≤10^5) (2≤n≤105,n−1≤m≤105,1≤u,v≤n,1≤c,d,e,w≤105) (The graph has no self-loop , no repeated edges , and is connected)
Output a line for the minimum cost. Output − 1 -1 −1 if she can’t reach.
5 7 1 1 1 1 2 1 1 3 5 1 4 1 2 3 2 2 4 5 3 4 3 3 5 5
5
有 n n n个点,编号从 1 1 1到 n n n,有 m m m条边,每条边有一个长度 w w w。 A l i c e Alice Alice有一艘飞船, A l i c e Alice Alice可以给它升级很多次(无限),每升级一次需要花费 c c c,升级一次之后飞船单次可飞行距离增加 d d d,可飞行次数增加 e e e。如果飞船需要飞过一条边,就需要满足单次可飞行距离 ≥ ≥ ≥这条路的长度同时可飞行次数不为 0 0 0。 现在 A l i c e Alice Alice在编号为 1 1 1的点,她的飞船为 0 0 0级,单次可飞行距离和可飞行次数都为 0 0 0,请你求出最小的花费使得 A l i c e Alice Alice可以到达 n n n点,如果不能到达 n n n则输出 − 1 -1 −1。 输入保证图联通,没有自环,没有重边。
菜是原罪,人生第一次 i c p c icpc icpc因为我这题没写出来带着队友打铁了,赛后看了一下大佬的思路才会的。 观察输入数据的数据范围可以知道最多有 1 ∗ 1 0 5 1*10^5 1∗105条边,边的长度最长也就是 1 ∗ 1 0 5 1*10^5 1∗105,这也就说明最多升级 1 ∗ 1 0 5 1*10^5 1∗105次是肯定够的,又因为是联通图,所以输出 − 1 -1 −1的情况是不存在的,因为可以无限次升级,怎么样都能到达 n n n点,就是花费的问题。 那么我们就可以对升级次数进行二分,然后 b f s bfs bfs走一遍看看能不能到达 n n n点,如果当前的升级次数可以到达 n n n则更新最小的升级次数,最后输出 c c c*最小升级次数就 o k ok ok了。 最后记得用 l o n g l o n g long\ long long long,不然会爆 i n t int int导致 w a wa wa。