Codevs 4600 [NOI2015] program automatic analysis

Source: Internet
Author: User

The number of points is very large, can not be saved, but fewer points, so the use of discretization, and then use and check set.

Discretization with map, over 8 points, 2 timeouts

Code:

#include <iostream>#include<cstring>#include<algorithm>#include<map>#defineSize 1000005*2using namespaceStd;map<int,int>dic;structin{intX,y,e;} Data[size];intf[size*2];inten[size][2]; intCnt=0;intNBOOLFlag;intPa[size];voidinit () { for(intI=1; i<size;i++) pa[i]=i; memset (EN,0,sizeof(en));}intFindintx) {    if(X!=pa[x]) pa[x]=find (pa[x]); returnpa[x];}BOOLQueryintXinty) {    returnFind (x) = =find (y);}voidUnintXinty) {    if(Query (x, y))return; Pa[find (x)]=find (y); }intMain () {intT;cin>>T;  while(t--) {flag=true; Cnt=0;                Init (); CIN>>N;  for(intI=1; i<=n;i++) {cin>>data[i].x>>data[i].y>>DATA[I].E; f[2*i-1]=data[i].x; f[2*i]=data[i].y; } sort (F+1, f+1+n*2);  for(intI=1; i<=n*2; i++){            if(f[i]!=f[i-1]) {CNT++; Dic[f[i]]=CNT; }        }                intE,x,y; intnum=0;  for(intI=1; i<=n;i++) {x=dic[data[i].x]; Y=DIC[DATA[I].Y]; E=DATA[I].E; if(e==1) un (x, y); Else{num++; en[num][0]=x; en[num][1]=y; }        }         for(intI=1; i<=num;i++) {x=en[i][0]; y=en[i][1]; if(query (x, y)) {flag=false;  Break; }        }        if(flag) cout<<"YES"<<Endl; Elsecout<<"NO"<<Endl; }} 

Codevs 4600 [NOI2015] program automatic analysis

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.