[POJ] The Suspects (bare parallel query set), pojthesuspects

Source: Internet
Author: User

[POJ] The Suspects (bare parallel query set), pojthesuspects

And query the template questions of the set. To avoid the trouble, the root node is merged to a small node When merged.

# Include <cstdio> # include <algorithm> using namespace std; const int maxn = 33333; int fa [maxn]; int num [maxn]; int n, m, t; void init () {for (int I = 0; I <n; I ++) {fa [I] = I; num [I] = 1 ;}} int find_father (int u) {return fa [u] = u? U: fa [u] = find_father (fa [u]);} int main () {while (scanf ("% d", & n, & m )) {if (! M &&! N) break; init (); for (int I = 0; I <m; I ++) {scanf ("% d", & t); int x, y; for (int j = 0; j <t; j ++) {scanf ("% d", & y); if (! J) x = y; else {int fy = find_father (y); int fx = find_father (x); if (fy> fx) swap (fy, fx ); // to avoid the trouble, merge the small root into the large root if (fy! = Fx) {fa [fy] = fx; num [fx] + = num [fy] ;}}t = find_father (0 ); printf ("% d \ n", num [t]);} return 0 ;}


What are the uses and query sets of Peking University acm questions?

POJ 1611 The Suspects most basic query set

POJ 2524 basic Ubiquitous Religions query set
POJ 1182 extension of food chain and query set
Note: There is only one group of data;
Make full use of the conditions given by the question: there are three types of animals A, B, C, and the food chains of these three types of animals.
It constitutes an interesting ring. A eats B, B eats C, and C eats. That is to say, there are only three groups.
POJ 2492 A Bug's Life and expansion of query Sets
Method 1: depth-first Traversal
Each traversal record indicates whether the path is male or female. Only male-> female, female-> male meets the requirement. Otherwise, locate the homosexuality and end the program.
Method 2: Bipartite Graph Matching
Method 3: Expand the query set: it is very similar to 1182, but there are two groups, and 1182 is three groups, 1611 is not limited.
POJ 1861 Network = zju_1542 and query set + custom sorting + greedy search "minimal spanning tree"
The answer is not unique, but QSORT () and SORT () can be used on ZOJ, and only SORT () can be used on POJ...
POJ 1703 Find them, Catch them and query the expansion of the Set
This is very similar to POJ 2492 A Bug's Life, that is, the code will be AC after A slight modification!
Note: And of course, at least one of them belongs to Gang Dragon, and the same for Gang Snake. There are only two groups.
POJ 2236 Wireless Network and query set Application
Note: 1. Check the Set; 2. The range of N can be 1001; 3. From the N + 1 line, the first input can be a string.
POJ 1988 Cube Stacking and good query set Application
1. Like Galaxy hero legend = NOI2002 Galaxy; 2. An array behind [x] is added to record the relative position of warship x in the column; 3. For detailed problem report, see Galaxy hero legend.

JOJ 1905 Freckles = POJ 2560 Minimum Spanning Tree

Method 1: Prim algorithm; Method 2: Query sets to implement the Kruskar Algorithm for the Minimum Spanning Tree

. One of the suspects ________ down Zhongshan Road at 9:00 last night. A. was seen to run B. wa

Answer: B
Cause: 1. Use was instead of were because the subject of this sentence is one of the suspects. one of the suspects is singular. Therefore, C and D are excluded first. Then we can see whether it is to run or running. 2. First, this sentence provides a very specific time point, so it implies that the running action should be performed. Secondly, the sentence has already been said to be seen. For anyone else, at a very precise point in time, what you see must be the moment when the person is doing something. Similarly, yes. O. I don't know if it means white.
Hope to help you...

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.