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][ ...
随机推荐
- V9自定义分页函数
大家做网站的时候,可能很多时候分页样式都得根据模板的要求来控制的,这时很多人都会去修改全局文件phpcms\libs\functions \global.func.php里的pages()函数,这样问 ...
- 基于Jquery 的 Chart
Flot Flot一个纯javascript绘画库,基于jQuery开发.它能够在客户端根据任何数据集快速生成图片.目前只能绘制线状图和柱状. Flot jQuery jQchart 基于C ...
- easy ui datagrid在没有数据时显示相关提示内容
$(function () { $('#dg').datagrid({ fitColumns: true, url: 'product.json', pagination: true, pageSiz ...
- EXTJS4.2 控件之Grid 行点击事件
listeners: { 'itemclick': function (view, record, item, index, e) { //Ext.MessageBox.alert("标题& ...
- The ‘Microsoft.ACE.OLEDB.12.0′ provider is not registered on the local machine. (System.Data)
When you try to import Excel 2007 or later “.xlsx” files into an SQL Server 2008 database you may ge ...
- [转]popwindow用法
[转]弹出窗口的两种实现方式 PopupWindow 和 Activity 链接:http://www.cnblogs.com/winxiang/archive/2012/11/20/2778729 ...
- C# Path
http://hi.baidu.com/mayijun0410/item/4fa6c6c154a1c35ebdef69f9 using System.IO; Path类的静态方法: ChangeExt ...
- python top project of 2013
Hi Pythonistas! 测试和调试 Testing & Debugging 框架及Web Frameworks & Web 并发 Concurrency 任务调度 Job Sc ...
- Generating Huge reports in JasperReports
There are certain things to care while implementing the Jasper Reports for huge dataset to handle th ...
- HDU4548+素数
简单题. /* */ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<alg ...