zoukankan      html  css  js  c++  java
  • 并查集noi水题 (P1955 [NOI2015]程序自动分析)

    现将输入排序,把merge排在前面 ,避免冗余计算

     1    n=rd();
     2     FOR(i,1,n)
     3     {
     4         s[i].x=rd(),a[++tot]=s[i].x,
     5         s[i].y=rd(),a[++tot]=s[i].y,
     6         s[i].b=rd();
     7     }
     8     sort(s+1,s+n+1);
     9     sort(a+1,a+tot+1);
    10     tot=unique(a+1,a+tot+1)-a-1;
    12     FOR(i,1,tot) fa[i]=i;
    13     //map<hhh,int> mp;
    14     bool flag=1;
    15     FOR(i,1,n)
    16     {
    17       int xx=lower_bound(a+1,a+tot+1,s[i].x)-a;
    18       int yy=lower_bound(a+1,a+tot+1,s[i].y)-a;
    19       int gx=get(xx),gy=get(yy);
    20       if(s[i].b==1) fa[gx]=gy;
    26   else if(gx==gy)
    27       {flag=0;cout<<"NO"<<endl;break;}
    33 if(flag) cout<<"YES"<<endl;
  • 相关阅读:
    jdbc代码
    openwrt vsftp
    openwrt 配置samba && ubuntu 配置samba
    如何学习开源项目
    Makefile 笔记
    Samba 学习笔记
    quilt-补丁工具
    to-do-list
    新增feeds模块
    linux命令
  • 原文地址:https://www.cnblogs.com/universeplayer/p/10536371.html
Copyright © 2011-2022 走看看