中山培训第四题 2016.7.9
来源:互联网 发布:剑三重置版优化补丁 编辑:程序博客网 时间:2024/04/29 12:03
Description
N头牛要去参加一场在编号为x(1<=x<=n)的牛的农场举行的派对(1<=N<=1000),有M(1<=m<=100000)条有向道路,每条路长ti(1<=ti<=100);
每头牛都必须参加完派对后回到家,每头牛都会选择最短路径,求这n个牛的最短路径(一个来回)中最长的一条的长度。
特别提醒:可能有权值不同的重边。
Input
第1行: N,M,X;
第2~m+1行: Ai,Bi,Ti,表示有一条从Ai到Bi的路,长度为Ti.
Output
最长最短路的长度。
Sample Input
4 8 2
1 2 4
1 3 2
1 4 7
2 1 1
2 3 5
3 1 2
3 4 4
4 2 3
Sample Output
10
const
MaxE=100000;
MaxV=2000000;
type
rec=record
x,y,w,next:longint;
end;
var
n,m,c,q,i,x,y,w:longint;
g,g1:array [1..Maxv] of rec;
ls,ls1:array [1..Maxe] of longint;
v,d,list,s:array [1..maxe] of longint;
procedure spfa;
var
head,tail,t,i:longint;
begin
head:=0; tail:=1;
list[1]:=c;
fori:=1 to n do
d[i]:=maxlongint div 3;
d[c]:=0;
v[c]:=1;
whilehead<>tail do
begin
head:=head mod maxe+1;
t:=ls[list[head]];
while t>0 do
with g[t] do
begin
if d[x]+w<d[y] then
begin
d[y]:=d[x]+w;
if v[y]=0 then
begin
v[y]:=1;
tail:=tail mod maxe+1;
list[tail]:=y;
end;
end;
t:=next;
end;
v[list[head]]:=0;
end;
end;
procedure print;
vari:longint;
max:int64;
begin
max:=0;
fori:=1 to n do
ifs[i]+d[i]>max then max:=s[i]+d[i];
write(max);
end;
begin
read(n,m,c);
fori:=1 to n do ls[i]:=0;
fori:=1 to m do
begin
read(x,y,w);
g[i].x:=x;
g[i].y:=y;
g[i].w:=w;
g[i].next:=ls[x];
ls[x]:=i;
g1[i].x:=y;
g1[i].y:=x;
g1[i].w:=w;
g1[i].next:=ls1[y];
ls1[y]:=i;
end;
spfa;
s:=d;
g:=g1;
ls:=ls1;
spfa;
print;
end.
- 中山培训第四题 2016.7.9
- 中山培训 2016.7.9
- 中山培训第一题 2016.7.7
- 中山培训第二题 2016.7.7
- 中山培训 2016.7.11
- 中山培训 2016.7.11
- 中山培训 2016.7.11
- 中山培训(三题)
- 中山培训第三题(未解决)
- 据中山电商培训相中山电商培训
- 第四次培训
- 框架培训-第四日
- oracle培训第四天
- Java培训第四天
- 中山纪念中学套题(1)
- 北京微软培训第四天
- csdn二次培训 第四课
- 网络部第四次培训
- CTF 【每日一题 20160707】凯撒加密
- arcgis的破解安装
- CNN 卷积神经网络结构
- maven lib 复制到工程中
- NWU CCCC 1014(又是二叉树分冶)
- 中山培训第四题 2016.7.9
- popup
- 反转链表
- 堆和栈的区别(转过无数次的文章)
- Effective Java 进阶之路第一章(创建和销毁对象) 第一条(静态工厂方法)
- 从最大似然到EM算法浅解
- 268. Missing Number
- 使用imagecopyresampled 出现色差?
- 计算机网络知识点(谢希仁版教材) (扫盲帖)