bzoj1760 [Baltic2009]Triangulation
给定一个多边形的三角剖分(n<=1e5),且每个三角形有其颜色,问最多可以把这个三角剖分分成几个联通的部分,使任何一种颜色不出现在多个连通块中
建出三角剖分对应的树,同种颜色的点之间的路径是不能被切开的,因此将同色的点间路径标记一下,未标记的边数即为答案
具体实现可以用树上差分进行标记,树链剖分lca,同色的点按dfs序排序并将排序后相邻的点间路径标记
#include<cstdio>
#include<algorithm>
typedef long long i64;
const int R=5e6,N=,P=;
char buf[R],*ptr=buf-;
int _(){
int x=,c=*++ptr;
while(c<)c=*++ptr;
while(c>)x=x*+c-,c=*++ptr;
return x;
}
long long hx[P];
int hy[P];
int n,ans=-;
int e[N][],ep[N],col[N],cc[N],*cl[N],*cr[N],_c[N],*cp=_c,v[N];
int fa[N],sz[N],son[N],dep[N],top[N],id[N],idp=;
void chk(int a,int b,int id){
if(a>b)std::swap(a,b);
i64 h=i64(a)<<|b;
int w=h%P;
while(hy[w]){
if(hx[w]==h){
e[hy[w]][ep[hy[w]]++]=id;
e[id][ep[id]++]=hy[w];
return;
}
if((w+=)>=P)w-=P;
}
hx[w]=h;hy[w]=id;
}
void f1(int w,int pa){
fa[w]=pa;
dep[w]=dep[pa]+;
sz[w]=;
for(int i=;i<ep[w];++i){
int u=e[w][i];
if(u==pa)continue;
f1(u,w);
sz[w]+=sz[u];
if(sz[son[w]]<sz[u])son[w]=u;
}
}
void f2(int w,int tp){
top[w]=tp;
id[w]=++idp;
if(son[w])f2(son[w],tp);
for(int i=;i<ep[w];++i){
int u=e[w][i];
if(u==fa[w]||u==son[w])continue;
f2(u,u);
}
}
void f3(int w){
for(int i=;i<ep[w];++i){
int u=e[w][i];
if(u==fa[w])continue;
f3(u);
v[w]+=v[u];
}
if(!v[w])++ans;
}
int lca(int x,int y){
int a=top[x],b=top[y];
while(a!=b){
if(dep[a]<dep[b])std::swap(a,b),std::swap(x,y);
x=fa[a];a=top[x];
}
return dep[x]<dep[y]?x:y;
}
bool cmp(int a,int b){
return id[a]<id[b];
}
int main(){
fread(buf,,R,stdin);
n=_()-;
for(int i=;i<=n;++i){
int a=_(),b=_(),c=_();
chk(a,b,i);
chk(a,c,i);
chk(c,b,i);
++cc[col[i]=_()];
}
for(int i=;i<=n;++i)cl[i]=cr[i]=cp,cp+=cc[i];
for(int i=;i<=n;++i)*(cr[col[i]]++)=i;
f1(,);
f2(,);
for(int i=;i<=n;++i)if(cl[i]!=cr[i]){
std::sort(cl[i],cr[i],cmp);
for(int p=;p<cc[i];++p){
int x=cl[i][p],y=cl[i][p-],z=lca(x,y);
++v[x];++v[y];v[z]-=;
}
}
f3();
printf("%d",ans);
return ;
}
bzoj1760 [Baltic2009]Triangulation的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Delaunay Triangulation in OpenCascade
Delaunay Triangulation in OpenCascade eryar@163.com 摘要:本文简要介绍了Delaunay三角剖分的基础理论,并使用OpenCascade的三角剖分算 ...
- bzoj1355: [Baltic2009]Radio Transmission
将原串看成是循环节的后缀加上若干个循环节,那么考虑每种情况都会发现n-next[n]就是最小循环节.(一开始总输出n...然后发现build_next连调用都没有,%%% #include<cs ...
- bzoj 1761: [Baltic2009]beetle 区间dp
1761: [Baltic2009]beetle Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 255 Solved: 92[Submit][Statu ...
- BZOJ 1355: [Baltic2009]Radio Transmission( kmp )
自己YY一下可以发现answer = n - fail[ n ] ------------------------------------------------------------------ ...
- uva 1331 - Minimax Triangulation(dp)
option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4077&mosm ...
- OpenCASCADE BRepMesh - 2D Delaunay Triangulation
OpenCASCADE BRepMesh - 2D Delaunay Triangulation eryar@163.com Abstract. OpenCASCADE package BRepMes ...
- BZOJ 1355: [Baltic2009]Radio Transmission [KMP 循环节]
1355: [Baltic2009]Radio Transmission Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 792 Solved: 535 ...
- [Baltic2009]Radio Transmission
bzoj 1355: [Baltic2009]Radio Transmission http://www.lydsy.com/JudgeOnline/problem.php?id=1355 Time ...
随机推荐
- 配置Hadoop的Eclipse开发环境
前言 在先前的文章中,已经介绍了如何在Ubuntu Kylin操作系统下搭建Hadoop运行环境,而现在将在之前工作的基础上搭建Eclipse开发环境. 配置 开发环境:Eclipse 4.2 其他同 ...
- 使用AjaxPro
1:后台注册 protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(ty ...
- ZOJ 1042 W’s Cipher
原题链接 题目大意:按照规则解码.26个字母分成三组,每一组按照顺时针移位编码.现在已知移动的位数,要求解码. 解法:以前看过一本古典密码学的书,百度贴吧密码吧也有很多经典的加密方法,想什么凯撒移位. ...
- Color Map的生成方法
/* Return a RGB colour value given a scalar v in the range [vmin,vmax] In this case each colour comp ...
- Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 【转】Android使用Log4j例子
Step 1 Download Log4J library from http://logging.apache.org/log4j/1.2/download.html Step 2 Configur ...
- 输入DStream和Receiver详解
输入DStream代表了来自数据源的输入数据流.在之前的wordcount例子中,lines就是一个输入DStream(JavaReceiverInputDStream),代表了从netcat(nc) ...
- HDU-4003 Find Metal Mineral (树形DP+分组背包)
题目大意:用m个机器人去遍历有n个节点的有根树,边权代表一个机器人通过这条边的代价,求最小代价. 题目分析:定义状态dp(root,k)表示最终遍历完成后以root为根节点的子树中有k个机器人时产生的 ...
- Get access to Servlet
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class LoginServlet extend ...
- 计算机算法-C语言-统计字母数字个数解
Question:输入一串以“?”结尾的字符,分别统计其中字母数字的个数,输出字母及数字的个数. Solve: #include<stdio.h> #include<stdlib.h ...