比赛 20160421x 评测结果 AAAWAAWWWW
题目名称 电子碰撞 最终得分 50
用户昵称 5007 运行时间 0.004 s
代码语言 Pascal 内存使用 0.29 MiB
提交时间 2016-04-21 21:28:50
显示代码纯文本
var
n,m,i,a,b,x,y,time,j,head,tail:longint;
p:array [0..20] of extended;
map:array [0..20,0..20]of integer;
f1:array [0..20] of integer;
f:array [0..20] of extended;
q1,q2,p1,p2:array [0..9000] of integer;
can:array             [0..9000] of extended;
g1,g2:extended;
procedure swap(x,y:integer);
var c:longint; a:real;
begin
a:=f[x]; f[x]:=f[y]; f[y]:=a;
c:=f1[x];f1[x]:=f1[y];f1[y]:=c;
end;
procedure off;
begin
for i:=1 to tail do if q1[i]=q2[i] then f[q1[i]]:=f[q1[i]]+can[i];
for i:=1 to n-1 do
for j:=i+1 to n do if f[i]<f[j] then swap(i,j);
for i:=1 to n do writeln(f1[i]);
halt;
end;
begin
assign(input,'electrics.in');reset(input);
assign(output,'electrics.out');rewrite(output);
read(n,m,a,b);
for i:=1 to m do
     begin
     read(x,y);
	 inc(map[x,0]); map[x,map[x,0]]:=y;
	 inc(map[y,0]);map[y,map[y,0]]:=x;
     end;
for i:=1 to n do begin read(p[i]);f1[i]:=i; end;
head:=0;tail:=1; q1[1]:=a;q2[1]:=b;can[1]:=1;p1[tail]:=a;p2[tail]:=b;
while (head<tail) do
     begin
	 inc(head);
	 a:=q1[head];b:=q2[head];
	 if a=b then   continue;
	 if can[head]<0.0000001 then continue;
	 if tail=9000 then off;
	 g1:=(1-p[a])/map[a,0];g2:=(1-p[b])/map[b,0];
	 for i:=1 to map[a,0] do
	 for j:=1 to map[b,0] do
	     begin
		 inc(tail);if tail=9000 then off;
		 q1[tail]:=map[a,i];q2[tail]:=map[b,j];
		 can[tail]:=can[head]*g1*g2;
		 p1[tail]:=a;p2[tail]:=b;
		 end;
	 for i:=1 to map[a,0] do
	     begin  inc(tail);if tail=9000 then off;
		 q1[tail]:=map[a,i];q2[tail]:=b;
		 can[tail]:=can[head]*g1*p[b];
		 p1[tail]:=a;p2[tail]:=b;
		 end;
	 for i:=1 to map[b,0] do
	     begin  inc(tail); if tail=9000 then off;
		 q1[tail]:=a;q2[tail]:=map[b,i];
		 can[tail]:=can[head]*p[a]*g2;
		 p1[tail]:=a;p2[tail]:=b;
		 p1[tail]:=a;p2[tail]:=b;
		 end;	
	 end;
	 OFF;
end.