Hdu 2473 junk-mail Filter (and set)

Source: Internet
Author: User

Test instructions

n messages need to be identified.

Two kinds of operations:

1. M X y:x and Y are the same message

2.S x:x is misjudged (meaning that X is "kicked out" by the set it is subordinate to, and the relationship of all other messages remains the same)

There are several kinds of mails at the end of the question.

Ideas:

The "merge" of the messages can be achieved by using the and check sets. But to "kick out" the individual x and then make sure that the other relationships are the same.

To get a double-layered structure, the first layer is used to describe the relationship before the message. The second layer is used to point to the first layer of the node.

The first layer is FA, and the second layer is VFA. When X is "kicked out", just add a new point to the first layer and then vfa[x] point to the new node.

The relationship between the original message was retained and the X was "kicked out" successfully.

Code:

intn,m;intfa[1200005];intvfa[100005];intFINDFA (intx) {    returnfa[x]==x?fa[x]:fa[x]=Findfa (fa[x]);}intMain () {intt=0;  while(SCANF ("%d%d", &n,&m), n| |L) {Rep (i,1, N) {Fa[i]=i; Vfa[i]=i; }        intcn=N;  while(m--){            Charope[5]; scanf ("%s", ope); if(ope[0]=='M'){                intb; scanf ("%d%d",&a,&b); intFX=FINDFA (vfa[a+1]); intFY=FINDFA (vfa[b+1]); if(fx!=FY) {FA[FX]=fy; }            }Else{                intx; scanf ("%d",&x); Vfa[x+1]=++cn; FA[CN]=cn; }} Map<int,int>MP;        Mp.clear (); intans=0; Rep (I,1, N) {            intt=Findfa (Vfa[i]); if(mp[t]==0) {Mp[t]=1; ++ans; }} printf ("Case #%d:%d\n",++T,ans); }    return 0;}

Hdu 2473 Junk-mail Filter (and 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.