玛丽卡(spfa)求指导
pascal吧
全部回复
仅看楼主
level 11
百星高照 楼主
var
n,m,i,a,b,t,head,tail,max,j:longint;
cost,sost:array[1..1000,1..1000] of longint;
dist:array[1..1000] of longint;
v:array[1..1000] of boolean;
q,p:array[1..1000] of longint;
procedure spfa(a,b:longint);
var x:longint;
begin
fillchar(v,sizeof(v),false);fillchar(q,sizeof(q),0);
for i:=1 to n do dist[i]:=maxlongint div 3;
head:=0;tail:=1;
v[a]:=true;q[tail]:=a;dist[a]:=0;
while head<>tail do
begin
head:=(head mod n)+1;
x:=q[head];
for i:=1 to n do
if (cost[x,i]>0) and (cost[x,i]+dist[x]<dist[i]) then
begin
dist[i]:=cost[x,i]+dist[x];
p[i]:=x;
if not(v[i]) then
begin
tail:=(tail mod n)+1;
q[tail]:=i;
v[i]:=true;
end;
end;
end;
if dist[1]>max then max:=dist[1];
end;
procedure spfa2(a,b:longint);
var x:longint;
begin
fillchar(v,sizeof(v),false);fillchar(q,sizeof(q),0);
for i:=1 to n do dist[i]:=maxlongint div 3;
head:=0;tail:=1;
v[a]:=true;q[tail]:=a;dist[a]:=0;
while head<>tail do
begin
head:=(head mod n)+1;
x:=q[head];
for i:=1 to n do
if (cost[x,i]>0) and (cost[x,i]+dist[x]<dist[i]) then
begin
dist[i]:=cost[x,i]+dist[x];
if not(v[i]) then
begin
tail:=(tail mod n)+1;
q[tail]:=i;
v[i]:=true;
end;
end;
end;
if dist[1]>max then max:=dist[1];
end;
begin
readln(n,m);
for i:=1 to m do
begin
readln(a,b,t);
cost[a,b]:=t;
cost[b,a]:=t;
end;
spfa(n,1);
max:=0;
j:=1;
while j<>n do
begin
sost[j,p[j]]:=cost[j,p[j]];
cost[j,p[j]]:=maxlongint div 3;
cost[p[j],j]:=maxlongint div 3;
spfa2(n,1);
cost[j,p[j]]:=sost[j,p[j]];
cost[p[j],j]:=sost[j,p[j]];
j:=p[j];
end;
writeln(max);
end.
2015年07月22日 02点07分 1
level 11
百星高照 楼主
只能过5个点,其他的答案错误
测试点#marica1.in 结果:AC内存使用量: 256kB 时间使用量: 1ms
测试点#marica10.in 结果:WA内存使用量: 4716kB 时间使用量: 645ms
测试点#marica2.in 结果:AC内存使用量: 256kB 时间使用量: 1ms
测试点#marica3.in 结果:WA内存使用量: 256kB 时间使用量: 0ms
测试点#marica4.in 结果:AC内存使用量: 368kB 时间使用量: 1ms
测试点#marica5.in 结果:WA内存使用量: 492kB 时间使用量: 1ms
测试点#marica6.in 结果:AC内存使用量: 620kB 时间使用量: 2ms
测试点#marica7.in 结果:WA内存使用量: 1004kB 时间使用量: 8ms
测试点#marica8.in 结果:AC内存使用量: 2412kB 时间使用量: 85ms
测试点#marica9.in 结果:WA内存使用量: 4080kB 时间使用量: 193ms
2015年07月22日 02点07分 2
level 11
百星高照 楼主
大神在哪里
2015年07月22日 09点07分 4
level 11
百星高照 楼主
题目描述 Description
给定一个序列a1,a2,…,an,如果存在i<j并且ai>aj,那么我们称之为逆序对,求逆序对的数目
数据范围:N<=105。Ai<=105。时间限制为1s。
输入描述 Input Description
第一行为n,表示序列长度,接下来的n行,第i+1行表示序列中的第i个数。
输出描述 Output Description
所有逆序对总数.
2015年07月25日 12点07分 7
用树状数组优化。。我试了试,可能是水不太满,只过了3个点,别的全部爆时间
2015年07月25日 12点07分
为什么问我这种水题。。
2015年07月25日 14点07分
这不树状数组秒之么。。
2015年07月25日 14点07分
1