记录编号 |
39350 |
评测结果 |
AAAAAAAAAAAA |
题目名称 |
聪明的推销员 |
最终得分 |
100 |
用户昵称 |
zhangchi |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.435 s |
提交时间 |
2012-07-09 15:12:17 |
内存使用 |
8.14 MiB |
显示代码纯文本
type
node=record
v,next:longint;
end;
var
i,j,k,n,p,r,ans,tot,temp,x,y,tail:longint;
q:array[1..3000] of boolean;
vis:array[1..3000] of boolean;
b:array[1..3000,1..3000] of boolean;
which,cost:array[1..3000] of longint;
f:array[1..3000] of longint;
a:array[1..10000] of node;
d:array[1..3000] of longint;
exist:array[1..3000] of boolean;
procedure insert(x,y:longint);
begin
inc(tot);
a[tot].next:=f[x];
f[x]:=tot;
a[tot].v:=y;
end;
procedure floodfill(x:longint);
var
t:longint;
begin
q[x]:=true;
vis[x]:=true;
b[which[i],x]:=true;
t:=f[x];
while t<>0 do
begin
if q[a[t].v]=false then
floodfill(a[t].v);
t:=a[t].next;
end;
end;
begin
assign(input,'salenet.in'); reset(input);
assign(output,'salenet.out'); rewrite(output);
readln(n);
readln(p);
for i:=1 to p do
begin
read(which[i]);
readln(cost[i]);
end;
readln(r);
for i:=1 to r do
begin
readln(x,y);
insert(x,y);
end;
for i:=1 to p do
begin
fillchar(q,sizeof(q),false);
floodfill(which[i]);
end;
for i:=1 to n do
if vis[i]=false then
begin
writeln('NO');
writeln(i);
close(input); close(output);
halt;
end;
for i:=1 to p do
begin
inc(tail);
d[tail]:=which[i];
exist[tail]:=true;
ans:=ans+cost[i];
temp:=tail-1;
for j:=1 to temp do
if exist[j] then
begin
if b[which[i],d[j]] and b[d[j],which[i]] then
begin
if cost[tail]>cost[j] then
begin
exist[tail]:=false;
dec(ans,cost[tail]);
break;
end
else
begin
exist[j]:=false;
dec(ans,cost[j]);
continue;
end;
end;
if b[which[i],d[j]] then
begin
exist[j]:=false;
dec(ans,cost[j]);
continue;
end;
if b[d[j],which[i]] then
begin
exist[tail]:=false;
dec(ans,cost[tail]);
break;
end;
end;
end;
writeln('YES');
writeln(ans);
close(input); close(output);
end.