NOI DAY1 T1 Program automatic analysis and search set + discretization

Source: Internet
Author: User

Test Instructions:There is no link Method:and search set + discretization parsing:Guo Sai this way to popularize the difficulty of the problem I am embarrassed to write the problem, the test instructions is very clear, one eye problem. In fact, all the requirements of a sort, put xi=xj conditions in front, so that the conditions of XI!=XJ put on the back of the line. And then we have all the i,j discretized for n queries, and here I'm slacking off with a map and just add all the XI=XJ parts to the set. XI!=XJ parts look at the two ancestors are not the same, the same as the next, the same output no; Code:This problem sticker code is really embarrassed--
#include <map>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 100100using namespace STD;intTotintTintNintfa[n<<1]; map<int,int>MstructNode {intX, Y, Z }a[n];intFindintx) {if(fa[x]==x)returnXElseFa[x]=find (Fa[x]);returnFA[X]; }intCMP (node A,node b) {returnA.z>b.z;}intMain () {scanf("%d", &t); while(t--) {tot=0; M.clear ();scanf("%d", &n); for(intI=1; i<=n;i++) {scanf("%d%d%d", &a[i].x,&a[i].y,&a[i].z); } for(intI=1; i<=n;i++) {if(!m[a[i].x]) M[a[i].x]=++tot;if(!m[a[i].y]) M[a[i].y]=++tot; } for(intI=1; i<=tot;i++) fa[i]=i;intflag=0; Sort (A +1, a+n+1, CMP); for(intI=1; i<=n;i++) {intX=M[A[I].X],Y=M[A[I].Y];intZ=a[i].z;if(z==1)              {intFx=find (x), Fy=find (y);if(FX!=FY)                  {fa[fx]=fy; }              }Else{intFx=find (x), Fy=find (y);if(FX==FY) {printf("no\n"); flag=1; Break;} }          }if(!flag)printf("yes\n"); }  }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

NOI DAY1 T1 Program automatic analysis and search set + discretization

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.