Merge of the vertical margin of the "CSS Foundation"

Source: Internet
Author: User

This topic refers to the great God, links as follows:

Http://www.cnblogs.com/kuangbin/archive/2012/08/30/2664419.html

There are also detailed answers to the categories and check sets, which are linked as follows:

http://www.cnblogs.com/wuyiqi/archive/2011/08/24/come__in.html

Topic links

The topics are as follows:

Dragon Balls Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2604 Accepted Submission (s): 1007


Problem Descriptionfive Hundred years later, the number of Dragon Balls would increase unexpectedly, so it ' s too difficult For Monkey King (WuKong) to gather all of the dragon balls together.

His country have n cities and there is exactly N dragon balls in the world. At first, for the ith Dragon Ball, the sacred Dragon would puts it in the ith city. Through long years, some cities ' Dragon Ball (s) would is transported to other cities. To save physical strength WuKong plans to take Flying Nimbus Cloud, a magical Flying cloud to gather dragon balls.
Every time WuKong would collect the information of one Dragon Ball, he'll ask you the information of the. You must tell him which city the ball was located and how many dragon balls was there in so city, you also need to tell H Im how many times the ball had been transported so far.
Inputthe first line of the input was a single positive integer T (0 < T <= 100).
For each case, the first line contains the Integers:n and Q (2 < N <= 10000, 2 < Q <= 10000).
Each of the following Q lines contains either a fact or a question as the follow format:
T A B:all The Dragon Balls which is in the same city with A has been transported to the city of the Bth ball in. You can assume that the cities is different.
Q A:wukong want to know X (the ID of the city Ath Ball are in), Y (the count of balls in Xth city) and Z (the tranporting Times of the Ath ball). (1 <= A, B <= N)
Outputfor each test case, output the test Case number formated as sample output. Then for each query, the output a line with three integers X Y Z saparated by a blank space.
Sample Input
3T 1 2T 3 2Q 4T 1 2Q 1T 1 3Q 1

Sample Output
Case 1:2 3 0Case 2:2 2 13 3 2

Authorpossessor WC
Source2010 acm-icpc multi-university Training Contest ()--host by HDU The idea is that the main number of times to be moved, and the number of moves = the number of times you moved + the number of times the Father node moved ...

And how many dragon beads are added directly to the ...

The code is as follows:

#include <cstdio>const int maxn=10000+10;int t,n,q;int root[maxn],count[maxn],move[maxn];int findroot (int x) {if    (root[x]!=x)        {int t=root[x];        Root[x]=findroot (Root[x]);    MOVE[X]+=MOVE[T]; } return root[x];}    void merge (int a,int b) {int fx=findroot (a);    int Fy=findroot (b);        if (fx!=fy) {root[fx]=fy;        COUNT[FY]+=COUNT[FX];        move[fx]=1;//here indicates that the Father node moves up to}}void FBI () {for (int i=1;i<=n;i++) {root[i]=i;        Count[i]=1;    move[i]=0;    }}int Main () {char str[2];    int A,b,cas;    scanf ("%d", &t);    cas=0;       while (scanf ("%d%d", &n,&q)!=eof) {cas++;       printf ("Case%d:\n", CAs);       FBI ();        while (q--) {scanf ("%s", str);            if (str[0]== ' T ') {scanf ("%d%d", &a,&b);        Merge (A, b);            } else {scanf ("%d", &a);            int T=findroot (a); printf ("%d%d%d\n", T,count[t],move[a]);       }}} return 0;} 


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.