bzoj1471

转化补集的思想,首先求出任意两点之间路径数目

然后求两条路径第一次相交在点k(按照拓扑排序的顺序)的数目,显然这里要用到容斥

然后pascal有坑爹的范围检测,所以运算中有些不会影响到答案但会爆int64的地方要判断一下

 const inf=1e18;
var w:array[..,..] of boolean;
f:array[..,..] of int64;
g:array[..] of int64;
q,rd:array[..] of longint;
a,b,c,d,n,m,x,y,i,j,k,h,t:longint;
ans:int64; begin
readln(n,m);
for i:= to m do
begin
readln(x,y);
w[x,y]:=true;
inc(rd[y]);
end;
for i:= to n do
if rd[i]= then
begin
inc(t);
q[t]:=i;
end;
h:=;
while h<=t do
begin
x:=q[h];
for i:= to n do
if w[x,i] then
begin
dec(rd[i]);
if rd[i]= then
begin
inc(t);
q[t]:=i;
end;
end; inc(h);
end;
readln(a,b,c,d);
for i:= to n do
for j:=i to n do
if q[i]=q[j] then f[q[i],q[j]]:=
else begin
for k:=i to j- do
if w[q[k],q[j]] then
if f[q[i],q[j]]+f[q[i],q[k]]<inf then f[q[i],q[j]]:=f[q[i],q[j]]+f[q[i],q[k]];
end; for i:= to n do
begin
if (f[q[i],b]<>) and (f[q[i],d]<>) then
begin
g[q[i]]:=f[a,q[i]]*f[c,q[i]];
for j:= to i- do
g[q[i]]:=g[q[i]]-g[q[j]]*f[q[j],q[i]]*f[q[j],q[i]];
end;
end;
for i:= to n do
ans:=ans-g[i]*f[i,b]*f[i,d];
ans:=ans+f[a,b]*f[c,d];
writeln(ans);
end.
上一篇:Perl调用外部命令的方式和区别


下一篇:RAC之常用方法-----新手入门