Codeforces Round #285 Div1 A and Div2 C

Source: Internet
Author: User

codeforces Round #285 Div1 A and Div2 Cproblemgive a figure g, make sure G is a forest (pit!) )。 Figure G contains n points, giving two attributes for each point: degrees (degree), XOR, and (sum). The degree indicates how many points the point is connected to, and the XOR of the number of points to which it is connected (the point number starts at 0, and if the degree is 0, the XOR is 0). Requires the original image, the number of output edges and the vertices at each end of each edge.
LimitsTime Limit (ms):Memory Limit (MB):N: [1, 2^16]degree: [0, N-1]
Solutionsince G is a forest, each connected graph of G must be a tree, and the tree must have no loop and no loop, topological sort. According to the method of topological sorting, the degree and XOR of the points are maintained, and the appropriate entry queue can be solved.
MoreAt first, the node entering the 1 into the queue, each time from the queue to take out the point (it may be assumed to be now), the degree of now must not exceed 1, if it is 1, then its XOR (sum) must be the number of points connected to it (may be assumed to); ^=now), then minus one to the degree of to, if minus one after the degree of to 1, then into the queue. This loops until the queue is empty. Now and to are each end vertex of an edge.
ComplexityTime complexity:o (N)Memory complexity:o (N)
Sourcecodeforces Round #285 Div1 A and Div2 C

Codecodeforces Round #285 Div1 A and Div2 C from My Github

Codeforces Round #285 Div1 A and Div2 C

Related Article

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.