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