具体可以见漆子超的论文

  1. /**************************************************************
  2.     Problem:
  3.     User: BLADEVIL
  4.     Language: Pascal
  5.     Result: Accepted
  6.     Time: ms
  7.     Memory: kb
  8. ****************************************************************/
  9.  
  10. //By BLADEVIL
  11. var
  12.     n, m                            :longint;
  13.     pre, other, len                 :array[..] of longint;
  14.     last                            :array[..] of longint;
  15.     l, top                          :longint;
  16.     size, stack, yy, ll             :array[..] of longint;
  17.     ff                              :array[..] of boolean;
  18.     root                            :longint;
  19.     b                               :array[..] of longint;
  20.     old                             :longint;
  21.     ans                             :longint;
  22.      
  23. procedure connect(x,y,z:longint);
  24. begin
  25.     inc(l);
  26.     pre[l]:=last[x];
  27.     last[x]:=l;
  28.     other[l]:=y;
  29.     len[l]:=z;
  30. end;
  31.  
  32.  
  33. procedure dfs_size(x,fa:longint);
  34. var
  35.     q, p                            :longint;
  36. begin
  37.     size[x]:=;
  38.     inc(top);
  39.     stack[top]:=x;
  40.     q:=last[x];
  41.     while q<> do
  42.     begin
  43.         p:=other[q];
  44.         if (ff[q]) or (p=fa) then
  45.         begin
  46.             q:=pre[q];
  47.             continue;
  48.         end;
  49.         dfs_size(p,x);
  50.         inc(size[x],size[p]);
  51.         q:=pre[q];
  52.     end;
  53.     yy[x]:=fa;
  54. end;
  55.  
  56. procedure getroot(u:longint);
  57. var
  58.     ms, s, x, p, q                  :longint;
  59.     i                               :longint;
  60. begin
  61.     top:=;
  62.     dfs_size(u,);
  63.     ms:=maxlongint;
  64.     for i:= to top do
  65.     begin
  66.         x:=stack[i];
  67.         s:=size[u]-size[x];
  68.         q:=last[x];
  69.         while q<> do
  70.         begin
  71.             p:=other[q];
  72.             if (ff[q]) or (p=yy[x]) then
  73.             begin
  74.                 q:=pre[q];
  75.                 continue;
  76.             end;
  77.             if size[p]>s then s:=size[p];
  78.             q:=pre[q];
  79.         end;
  80.         if s<ms then
  81.         begin
  82.             ms:=s;
  83.             root:=x;
  84.         end;
  85.     end;
  86. end;
  87.  
  88. procedure dfs_value(x,fa,lz,dep:longint);
  89. var
  90.     q, p                            :longint;
  91. begin
  92.     if lz>m then exit;
  93.     if dep>=ans then exit;
  94.     if b[m-lz]>= then
  95.         if b[m-lz]+dep<ans then ans:=b[m-lz]+dep;
  96.     if (b[lz]<) or (dep<b[lz]) then
  97.     begin
  98.         inc(top);
  99.         stack[top]:=lz;
  100.         ll[top]:=dep;
  101.     end;
  102.     q:=last[x];
  103.     while q<> do
  104.     begin
  105.         p:=other[q];
  106.         if (p=fa) or (ff[q]) then
  107.         begin
  108.             q:=pre[q];
  109.             continue;
  110.         end;
  111.         dfs_value(p,x,lz+len[q],dep+);
  112.         q:=pre[q];
  113.     end;
  114. end;
  115.  
  116. procedure solve(u:longint);
  117. var
  118.     i, q, p                         :longint;
  119.  
  120. begin
  121.     getroot(u);
  122.     if top= then exit;
  123.     top:=;
  124.     q:=last[root];
  125.     while q<> do
  126.     begin
  127.         p:=other[q];
  128.         if ff[q] then
  129.         begin
  130.             q:=pre[q];
  131.             continue;
  132.         end;
  133.         old:=top+;
  134.         dfs_value(p,root,len[q],);
  135.         for i:=old to top do
  136.             if (b[stack[i]]<) or (b[stack[i]]>ll[i]) then b[stack[i]]:=ll[i];
  137.         q:=pre[q];
  138.     end;
  139.      
  140.     for i:= to top do b[stack[i]]:=-;
  141.     q:=last[root];
  142.     while q<> do
  143.     begin
  144.         p:=other[q];
  145.         if ff[q] then
  146.         begin
  147.             q:=pre[q];
  148.             continue;
  149.         end;
  150.         ff[q]:=true;
  151.         ff[q xor ]:=true;
  152.         solve(p);
  153.         q:=pre[q];
  154.     end;
  155.          
  156. end;
  157.  
  158.      
  159. procedure main;
  160. var
  161.     i                               :longint;
  162.     x, y, z                         :longint;
  163.      
  164. begin
  165.     read(n,m);
  166.     l:=;
  167.     fillchar(b,sizeof(b),$ff);
  168.     b[]:=;   
  169.     for i:= to n- do
  170.     begin
  171.         read(x,y,z);
  172.         inc(x); inc(y);
  173.         connect(x,y,z);
  174.         connect(y,x,z);
  175.     end;
  176.     ans:=maxlongint;
  177.     solve();
  178.     if ans> then writeln(-) else writeln(ans);
  179. end;
  180.  
  181. begin
  182.     main;
  183. end.

bzoj 2599 数分治 点剖分的更多相关文章

  1. bzoj 2599(点分治)

    2599: [IOI2011]Race Time Limit: 70 Sec  Memory Limit: 128 MBSubmit: 3642  Solved: 1081[Submit][Statu ...

  2. BZOJ 2243 染色 | 树链剖分模板题进阶版

    BZOJ 2243 染色 | 树链剖分模板题进阶版 这道题呢~就是个带区间修改的树链剖分~ 如何区间修改?跟树链剖分的区间询问一个道理,再加上线段树的区间修改就好了. 这道题要注意的是,无论是线段树上 ...

  3. BZOJ 2599: [IOI2011]Race( 点分治 )

    数据范围是N:20w, K100w. 点分治, 我们只需考虑经过当前树根的方案. K最大只有100w, 直接开个数组CNT[x]表示与当前树根距离为x的最少边数, 然后就可以对根的子树依次dfs并更新 ...

  4. bzoj 2599 [IOI2011]Race (点分治)

    [题意] 问树中长为k的路径中包含边数最少的路径所包含的边数. [思路] 统计经过根的路径.假设当前枚举到根的第S个子树,若x属于S子树,则有: ans<-dep[x]+min{ dep[y] ...

  5. BZOJ 2599 [IOI2011]Race【Tree,点分治】

    给出N(1 <= N <= 200000)个结点的树,求长度等于K(1 <= K <= 1000000)的路径的最小边数. 点分治,这道题目和POJ 2114很接近,2114是 ...

  6. 【BZOJ 2599】【IOI 2011】Race 点分治

    裸的点分治,然而我因为循环赋值$s$时把$i <= k$写成$i <= n$了,WA了好长时间 #include<cstdio> #include<cstring> ...

  7. BZOJ 2599 Race(树分治)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2599 题意:给一棵树,每条边有权.求一条路径,权值和等于K,且边的数量最小. 题意:每次 ...

  8. bzoj 2599: [IOI2011]Race (点分治 本地过了就是过了.jpg)

    题面:(复制别人的...) Description 给一棵树,每条边有权.求一条路径,权值和等于K,且边的数量最小. Input 第一行 两个整数 n, k第二..n行 每行三个整数 表示一条无向边的 ...

  9. bzoj 2599: [IOI2011]Race【点分治】

    点分治,用一个mn[v]数组记录当前root下长为v的链的最小深度,每次新加一个儿子的时候都在原来儿子更新过的mn数组里更新ans(也就是查一下mn[m-dis[p]]+de[p]) 这里注意更新和初 ...

随机推荐

  1. 深入浅出MongoDB(二)概述

    上次的博文深入浅出MongoDB(一)NoSQL中我们已经简单介绍了一下NoSQL的基本概念,这次我们来了解一下MongoDB的相关概念. 1.简介 MongoDB是一款由C++编写的高性能.开源.无 ...

  2. css3圆角边框,边框阴影

    border-radius向元素添加圆角边框,css3中的.IE9+ chrome safari5+ firefox4+ 现在都支持.可以向input div等设置边框.与border相似,可以四个角 ...

  3. 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 ...

  4. UCOS2_STM32F1移植详细过程(一)

    Ⅰ.概述 该文写针对初学µC/OS的朋友,基于以下平台来一步一步移植µC/OS嵌入式操作系统.UCOS移植相关平台: 系统平台:µC/OS-II  (最新V2.92版) 硬件平台:STM32F1    ...

  5. programming ruby

    ri #rdoc reader attr_reader attr_writer @@xx 类变量都是私有的 def 类名.xx end 类方法 [1,3,5,7].inject(0){|sum,e| ...

  6. 快速同步mysql数据到redis中

    MYSQL快速同步数据到Redis 举例场景:存储游戏玩家的任务数据,游戏服务器启动时将mysql中玩家的数据同步到redis中. 从MySQL中将数据导入到Redis的Hash结构中.当然,最直接的 ...

  7. SQL注入式攻击

    百度百科:http://baike.baidu.com/link?url=GQbJ2amTzTahZA7XJSBDLYYkN3waQ9JCoJ0l--tCWlvKQibe0YaH4hpmgEnLyn0 ...

  8. hdu 1212 Big Number

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Big Number Description As we know, Big Number is ...

  9. Android的快速开发框架afinal

    afinal 是一个android的 orm 和 ioc 框架.而且封装了android中的httpClient,使其更加简单易用. afinal是android应用开发的终极框架. FinalDB使 ...

  10. JavaScript高级程序设计之location对象

    location对象用来处理URL的相关信息 1.获取查询字符串 // 获取查询字符串对象 var getQueryStringArgs = function () { ? location.sear ...