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][ ...
随机推荐
- ORA-12838: cannot read/modify an object after modifying it in parallel
insert /*+ append */ into my_all_objects select * from my_all_objects; select * from my_all_objects ...
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析(引用)
在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设备驱动程序请求处理内容的值.cmd除了可区别数字外,还包含有助于处理的几种相应信息. cmd的大小为 32位,共分 4 个 ...
- Get the item a SharePoint workflow task is associated with
This is handy. SharePoint helpfully populates the meta data with the GUID of the list and the ID of ...
- C# - dynamic 类型
C#4引入dynamic关键字,定义变量时,可以不初始化它的值. dynamic类型仅在编译期间存在,在运行期间会被System.Object类型替代. dynamic myDynamicVar; m ...
- C#学习笔记---基础入门(一)
C#中的变量: 一个变量就是存储区(内存)中的一个存储单元. 变量声明赋值:int money =1000;/int money;money=1000; 输出:console.writeLine(mo ...
- JS、C# 去除html标签
JS去除html标签 var str = "<span style="display:none;" mce_style="display:none;&qu ...
- 成功解决Tomcat-JDBC-MySQL乱码
0.MySQL-JDBC驱动文档 官方解释 1.数据库的字符编码和表内字段的编码 在MySQL中数据库的字符编码和表内字段的编码的要指定为utf8(utf8_general_ci) 2.jsp中 pa ...
- 《head first java 》读书笔记
Updated 2014/03/26 P300-P402 Updated 2014/03/25 P213-300 Updated 2014/03/20 P0-P213 对象本身已知的事物被称为: 实例 ...
- hdu 3032 Nim or not Nim? 博弈论
这题是Lasker’s Nim. Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g( ...
- navicat 导入sql文件乱码问题解决
一,右键数据库链接,点击链接属性,修改以下信息,如图: 选择高级选项页签==>去掉使用MySQL字符集复选框==>选择GB2312字符编码==>点击确定 三,控制台后,show va ...