Codeforces Gym Hello Div1 B and Div2 D

Source: Internet
Author: User

codeforces Gym Hello Div1 B and Div2 Dcodeforces Gym 100571 problem Dproblemto a graph g<v,e> and the source point S, the attributes of the edge are length L and color C, i.e. e=<l,c>. The Q-time query, given a point x, outputs the shortest length of the s to x (the output-1 is not present). But the path from S to X is not the same color as the two adjacent edges.
LimitsTime Limit (ms):Memory Limit (MB):| v|, | e|: [1, 10^5]X, S: [1, | v| ]L: [1, 10^9]| c|: [1, 10^5]Q: [1, 10^5]
SolutionThe V=<minlen,mincolor,secondlen,secondcolor>;minlen represents the shortest short-circuit length of Point V, and Mincolor represents the color of the last edge of the shortest path, The Secondlen represents the secondary short-circuit length of Point V, and Secondcolor represents the color of the last edge of the secondary short circuit. Note that it is important to make sure that Mincolor is different from Secondcolor at any time. With the SPFA algorithm, the initial source points are added to the queue, each time it is taken from the queue, updated to all points that can be reached, and the points are properly added to the queue. Set E as the current edge, now for the current point, to the point to be updated, and if now's Mincolor and e are different, update with the smallest edge of now, otherwise update with Now's minor edge (if present), and until the queue is empty, the shortest path length of the source point S to all points is calculated.
Morewithout losing its generality, assuming that the current minimum edge of now is updated, if now.minlen+e.len< To.minlen, the minimum edge of the to is updated, but note that at this point it may be necessary to replace the smallest edge to the minor edge of the to, provided the E.color is different from to.mincolor; if Now.minlen+e.len>=to.minlen and Now.minlen+e.len<to.secondlen, the minor side of the to is updated, but only if E.color is different from To.mincolor. Updates the color at the same time as the Edge Len is updated. Updating with Now's minor edge is similar to updating with Now's minimum edge, but only if the secondary small edge of now exists. Each time the to is updated, if to is not in the queue, join the queue.
ComplexityTime Complexity:o (k*| e|) (k small)Memory Complexity:o (| v|+| e|)
Sourcecodeforces Gym Hello Div1 B and Div2 D

Codecodeforces Gym Hello Div1 B and Div2 D from My Github

Codeforces Gym Hello Div1 B and Div2 D

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.