bzoj 2599 数分治 点剖分
具体可以见漆子超的论文
- /**************************************************************
- Problem:
- User: BLADEVIL
- Language: Pascal
- Result: Accepted
- Time: ms
- Memory: kb
- ****************************************************************/
- //By BLADEVIL
- var
- n, m :longint;
- pre, other, len :array[..] of longint;
- last :array[..] of longint;
- l, top :longint;
- size, stack, yy, ll :array[..] of longint;
- ff :array[..] of boolean;
- root :longint;
- b :array[..] of longint;
- old :longint;
- ans :longint;
- procedure connect(x,y,z:longint);
- begin
- inc(l);
- pre[l]:=last[x];
- last[x]:=l;
- other[l]:=y;
- len[l]:=z;
- end;
- procedure dfs_size(x,fa:longint);
- var
- q, p :longint;
- begin
- size[x]:=;
- inc(top);
- stack[top]:=x;
- q:=last[x];
- while q<> do
- begin
- p:=other[q];
- if (ff[q]) or (p=fa) then
- begin
- q:=pre[q];
- continue;
- end;
- dfs_size(p,x);
- inc(size[x],size[p]);
- q:=pre[q];
- end;
- yy[x]:=fa;
- end;
- procedure getroot(u:longint);
- var
- ms, s, x, p, q :longint;
- i :longint;
- begin
- top:=;
- dfs_size(u,);
- ms:=maxlongint;
- for i:= to top do
- begin
- x:=stack[i];
- s:=size[u]-size[x];
- q:=last[x];
- while q<> do
- begin
- p:=other[q];
- if (ff[q]) or (p=yy[x]) then
- begin
- q:=pre[q];
- continue;
- end;
- if size[p]>s then s:=size[p];
- q:=pre[q];
- end;
- if s<ms then
- begin
- ms:=s;
- root:=x;
- end;
- end;
- end;
- procedure dfs_value(x,fa,lz,dep:longint);
- var
- q, p :longint;
- begin
- if lz>m then exit;
- if dep>=ans then exit;
- if b[m-lz]>= then
- if b[m-lz]+dep<ans then ans:=b[m-lz]+dep;
- if (b[lz]<) or (dep<b[lz]) then
- begin
- inc(top);
- stack[top]:=lz;
- ll[top]:=dep;
- end;
- q:=last[x];
- while q<> do
- begin
- p:=other[q];
- if (p=fa) or (ff[q]) then
- begin
- q:=pre[q];
- continue;
- end;
- dfs_value(p,x,lz+len[q],dep+);
- q:=pre[q];
- end;
- end;
- procedure solve(u:longint);
- var
- i, q, p :longint;
- begin
- getroot(u);
- if top= then exit;
- top:=;
- q:=last[root];
- while q<> do
- begin
- p:=other[q];
- if ff[q] then
- begin
- q:=pre[q];
- continue;
- end;
- old:=top+;
- dfs_value(p,root,len[q],);
- for i:=old to top do
- if (b[stack[i]]<) or (b[stack[i]]>ll[i]) then b[stack[i]]:=ll[i];
- q:=pre[q];
- end;
- for i:= to top do b[stack[i]]:=-;
- q:=last[root];
- while q<> do
- begin
- p:=other[q];
- if ff[q] then
- begin
- q:=pre[q];
- continue;
- end;
- ff[q]:=true;
- ff[q xor ]:=true;
- solve(p);
- q:=pre[q];
- end;
- end;
- procedure main;
- var
- i :longint;
- x, y, z :longint;
- begin
- read(n,m);
- l:=;
- fillchar(b,sizeof(b),$ff);
- b[]:=;
- for i:= to n- do
- begin
- read(x,y,z);
- inc(x); inc(y);
- connect(x,y,z);
- connect(y,x,z);
- end;
- ans:=maxlongint;
- solve();
- if ans> then writeln(-) else writeln(ans);
- end;
- begin
- main;
- end.
bzoj 2599 数分治 点剖分的更多相关文章
- bzoj 2599(点分治)
2599: [IOI2011]Race Time Limit: 70 Sec Memory Limit: 128 MBSubmit: 3642 Solved: 1081[Submit][Statu ...
- BZOJ 2243 染色 | 树链剖分模板题进阶版
BZOJ 2243 染色 | 树链剖分模板题进阶版 这道题呢~就是个带区间修改的树链剖分~ 如何区间修改?跟树链剖分的区间询问一个道理,再加上线段树的区间修改就好了. 这道题要注意的是,无论是线段树上 ...
- BZOJ 2599: [IOI2011]Race( 点分治 )
数据范围是N:20w, K100w. 点分治, 我们只需考虑经过当前树根的方案. K最大只有100w, 直接开个数组CNT[x]表示与当前树根距离为x的最少边数, 然后就可以对根的子树依次dfs并更新 ...
- bzoj 2599 [IOI2011]Race (点分治)
[题意] 问树中长为k的路径中包含边数最少的路径所包含的边数. [思路] 统计经过根的路径.假设当前枚举到根的第S个子树,若x属于S子树,则有: ans<-dep[x]+min{ dep[y] ...
- BZOJ 2599 [IOI2011]Race【Tree,点分治】
给出N(1 <= N <= 200000)个结点的树,求长度等于K(1 <= K <= 1000000)的路径的最小边数. 点分治,这道题目和POJ 2114很接近,2114是 ...
- 【BZOJ 2599】【IOI 2011】Race 点分治
裸的点分治,然而我因为循环赋值$s$时把$i <= k$写成$i <= n$了,WA了好长时间 #include<cstdio> #include<cstring> ...
- BZOJ 2599 Race(树分治)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2599 题意:给一棵树,每条边有权.求一条路径,权值和等于K,且边的数量最小. 题意:每次 ...
- bzoj 2599: [IOI2011]Race (点分治 本地过了就是过了.jpg)
题面:(复制别人的...) Description 给一棵树,每条边有权.求一条路径,权值和等于K,且边的数量最小. Input 第一行 两个整数 n, k第二..n行 每行三个整数 表示一条无向边的 ...
- bzoj 2599: [IOI2011]Race【点分治】
点分治,用一个mn[v]数组记录当前root下长为v的链的最小深度,每次新加一个儿子的时候都在原来儿子更新过的mn数组里更新ans(也就是查一下mn[m-dis[p]]+de[p]) 这里注意更新和初 ...
随机推荐
- 深入浅出MongoDB(二)概述
上次的博文深入浅出MongoDB(一)NoSQL中我们已经简单介绍了一下NoSQL的基本概念,这次我们来了解一下MongoDB的相关概念. 1.简介 MongoDB是一款由C++编写的高性能.开源.无 ...
- css3圆角边框,边框阴影
border-radius向元素添加圆角边框,css3中的.IE9+ chrome safari5+ firefox4+ 现在都支持.可以向input div等设置边框.与border相似,可以四个角 ...
- public void onItemClick(AdapterView arg0, View view, int position,long arg3)详解【整理自网络】
参考自: http://blog.csdn.net/zwq1457/article/details/8282717 http://blog.iamzsx.me/show.html?id=147001 ...
- UCOS2_STM32F1移植详细过程(一)
Ⅰ.概述 该文写针对初学µC/OS的朋友,基于以下平台来一步一步移植µC/OS嵌入式操作系统.UCOS移植相关平台: 系统平台:µC/OS-II (最新V2.92版) 硬件平台:STM32F1 ...
- programming ruby
ri #rdoc reader attr_reader attr_writer @@xx 类变量都是私有的 def 类名.xx end 类方法 [1,3,5,7].inject(0){|sum,e| ...
- 快速同步mysql数据到redis中
MYSQL快速同步数据到Redis 举例场景:存储游戏玩家的任务数据,游戏服务器启动时将mysql中玩家的数据同步到redis中. 从MySQL中将数据导入到Redis的Hash结构中.当然,最直接的 ...
- SQL注入式攻击
百度百科:http://baike.baidu.com/link?url=GQbJ2amTzTahZA7XJSBDLYYkN3waQ9JCoJ0l--tCWlvKQibe0YaH4hpmgEnLyn0 ...
- hdu 1212 Big Number
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Big Number Description As we know, Big Number is ...
- Android的快速开发框架afinal
afinal 是一个android的 orm 和 ioc 框架.而且封装了android中的httpClient,使其更加简单易用. afinal是android应用开发的终极框架. FinalDB使 ...
- JavaScript高级程序设计之location对象
location对象用来处理URL的相关信息 1.获取查询字符串 // 获取查询字符串对象 var getQueryStringArgs = function () { ? location.sear ...