HDU 3635 Dragon Balls with right and check set

Source: Internet
Author: User

I thought it was quite advanced and looked at the set, it was a flood problem,

N Cities n Balls, M queries, t means the ball of the same city as the X number is transferred to the city where Y Ball is located, Q indicates the city in which the X ball is asked, how many balls the city has, and the X-ball has been transferred several times.

1#include <iostream>2#include <cstdio>3#include <fstream>4#include <algorithm>5#include <cmath>6#include <deque>7#include <vector>8#include <queue>9#include <string>Ten#include <cstring> One#include <map> A#include <stack> -#include <Set> - #defineLL Long Long the #defineEPS 1e-8 - #defineINF 0x3f3f3f3f - #defineOpen_file - #defineMAXN 10005 + using namespacestd; - intN, M; + intFATHER[MAXN], STEP[MAXN], NUM[MAXN]; A //Step[x] Indicates how many times x has moved, Num[x] indicates that there are several balls in the X city at intFindintx) { -     if(Father[x] = = x)returnx; -     inty =Father[x]; -FATHER[X] =find (Father[x]); -STEP[X] + =Step[y]; -     returnFather[x]; in } -  to intMain () + { - #ifdef Open_file theFreopen ("In.txt","R", stdin); *     //freopen ("OUT.txt", "w", stdout); $ #endif //Open_filePanax Notoginseng     intT; -scanf"%d", &T); the      for(intCAS =1; CAS <= T; cas++){ +scanf"%d%d", &n, &m); A          for(inti =1; I <= N; i++){ theFather[i] =i; +Step[i] =0; -Num[i] =1; $         } $printf"Case %d:\n", CAs); -         Charch; -         intx, y; the          for(inti =1; I <= m; i++){ -scanf"\ n");Wuyiscanf"%c", &ch); the             if(ch = ='T'){ -scanf"%d%d", &x, &y); Wu                 //move all the balls in the same city as X to the city where Y is located -                 intA = find (x), B =find (y); AboutNUM[B] + =Num[a]; $Num[a] =0; -step[a]++; -Father[a] =b; -             } A             if(ch = ='Q'){ +scanf"%d", &x); the                 intA =find (x); -printf"%d%d%d\n", A, num[a], step[x]); $             } the         } the     } the}

HDU 3635 Dragon Balls with right and check set

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.