NOI2003 逃学的小孩
这一题不会做啊……
我觉得真要比赛的话我可能会随机上几万次,然后再用LCA求距离,更新最优值,等到快超时的时候输出答案……
题解请看2007年陈瑜希论文
代码:
const maxn=;
type node=record
w,go,next:longint;
end;
var e:array[..maxn] of node;
f:array[..maxn,..] of int64;
first,u:array[..maxn] of longint;
i,x,y,z,n,tot,m:longint;
ans:int64;
function max(x,y:int64):int64;
begin
if x>y then exit(x) else exit(y);
end;
function get(x,y,z:int64):int64;
begin
get:=x+*y+z;
end;
procedure insert(x,y,z:longint);
begin
inc(tot);e[tot].go:=y;e[tot].w:=z;e[tot].next:=first[x];first[x]:=tot;
end;
procedure init;
begin
readln(n,m);
for i:= to m do
begin
readln(x,y,z);
insert(x,y,z);
insert(y,x,z);
end;
end;
procedure update(x,y:int64);
begin
if y>f[x,] then
begin
f[x,]:=f[x,];
f[x,]:=f[x,];
f[x,]:=y;
end
else
if y>f[x,] then
begin
f[x,]:=f[x,];
f[x,]:=y;
end
else
f[x,]:=max(f[x,],y);
end;
procedure dfs1(x,fa:longint);
var i,y:longint;
begin
i:=first[x];
while i<> do
begin
y:=e[i].go;
if y<>fa then
begin
dfs1(y,x);
u[y]:=e[i].w;
update(x,f[y,]+u[y]);
end;
i:=e[i].next;
end;
end;
procedure dfs2(x,fa:longint);
var i,y:longint;
begin
if f[x,]+u[x]=f[fa,] then update(x,f[fa,]+u[x])
else update(x,f[fa,]+u[x]);
ans:=max(ans,get(f[x,],f[x,],f[x,]));
i:=first[x];
while i<> do
begin
y:=e[i].go;
if y<>fa then dfs2(y,x);
i:=e[i].next;
end;
end;
procedure main;
begin
ans:=;
dfs1(,);
dfs2(,);
writeln(ans);
end;
begin
init;
main;
end.
唉,这种神题,我什么时候才能自己想到呢?
NOI2003 逃学的小孩的更多相关文章
- BZOJ 1509: [NOI2003]逃学的小孩( 树形dp )
树形dp求出某个点的最长3条链a,b,c(a>=b>=c), 然后以这个点为交点的最优解一定是a+2b+c.好像还有一种做法是求出树的直径然后乱搞... ----------------- ...
- 【BZOJ1509】[NOI2003]逃学的小孩 直径
[BZOJ1509][NOI2003]逃学的小孩 Description Input 第一行是两个整数N(3 N 200000)和M,分别表示居住点总数和街道总数.以下M行,每行给出一条街道的 ...
- [NOI2003]逃学的小孩(树的直径)
[NOI2003]逃学的小孩 题目描述 Chris家的电话铃响起了,里面传出了Chris的老师焦急的声音:"喂,是Chris的家长吗?你们的孩子又没来上课,不想参加考试了吗?"一听 ...
- 洛谷 P4408 [NOI2003]逃学的小孩
题目传送门 题目描述 Chris家的电话铃响起了,里面传出了Chris的老师焦急的声音:“喂,是Chris的家长吗?你们的孩子又没来上课,不想参加考试了吗?”一听说要考试,Chris的父母就心急如焚, ...
- 1509: [NOI2003]逃学的小孩 - BZOJ
Description Input 第一行是两个整数N(3 N 200000)和M,分别表示居住点总数和街道总数.以下M行,每行给出一条街道的信息.第i+1行包含整数Ui.Vi.Ti(1Ui ...
- BZOJ 1509: [NOI2003]逃学的小孩
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1509 直接求出树的直径,枚举每个点更新一遍答案. #include<cstring> ...
- 解题报告 『[NOI2003]逃学的小孩(树上操作)』
原题地址 今天翻看集训队巨佬写的一篇有关于树形动规的论文时看到了这道题,但感觉并不需要用动规,求出树的直径再暴力枚举一下就搞出来了. 其实是因为我太弱了,看不懂大佬在写什么orz 代码实现如下: #i ...
- LUOGU P4408 [NOI2003]逃学的小孩(树的直径)
题目描述 Chris家的电话铃响起了,里面传出了Chris的老师焦急的声音:“喂,是Chris的家长吗?你们的孩子又没来上课,不想参加考试了吗?”一听说要考试,Chris的父母就心急如焚,他们决定在尽 ...
- BZOJ1509 [NOI2003]逃学的小孩 树型DP
题目: 分析: 首先明确我们是要求 min(dist[C][A],dist[C][B])+dist[A][B]. 我们把C当成树根,第一我们可以发现min里面取dist[C][A]或者dist[C][ ...
随机推荐
- PHP获取搜索引擎关键字来源(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)
<?php //获取来自搜索引擎入站时的关键词 function get_keyword($url,$kw_start) { $start=stripos($url,$kw_start); $u ...
- linux 输入子系统(2)----简单实例分析系统结构(input_dev层)
实例代码如下: #include <linux/input.h> #include <linux/module.h> #include <linux/init.h> ...
- Java中的异常处理(一)
package second; public class C { public static void main(String[] args){ String name = null;//定义一个nu ...
- 微软职位内部推荐-SENIOR PRODUCER
微软近期Open的职位: Role Based in Shanghai, ChinaTitle: ProducerWe are seeking a Senior Producer to lead Pr ...
- google calendar api v3
google api for .net nuget Install-Package Google.Apis.Calendar.v3 oauth2 for asp.net http://www.code ...
- 3.3 spring-meta子元素的使用与解析
1. meta元素的使用 在解析元数据的分析之前,我们先回顾一下 meta属性的使用: <bean id="car" class="test.CarFactoryB ...
- mybatis 的<![CDATA[ ]]>
示例: xml文件: <!-- 获取条数 --> <select id="getCount" parameterType="Map" resu ...
- 团体程序设计天梯赛-练习集L1-019. 谁先倒
L1-019. 谁先倒 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳 ...
- <转>struts2中Convention中的basePackage与locators配置种种
用了Convention插件来实现所谓的0配置, 1. struts.convention.package.locators.basePackage=com.ZTest.web.action 这个属性 ...
- hdu 4403
水水的dfs #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath& ...