显示代码纯文本
program P2098;
type
roads=record
toit,next:longint;
end;
var
road:array[1..2010] of roads;
list:array[1..1010] of longint;
flag:array[1..1010] of boolean;
n,q,i,u,v,s,t,cnt:longint;
procedure add(u,v:longint);
begin
inc(cnt);
road[cnt].toit:=v;
road[cnt].next:=list[u];
list[u]:=cnt;
end;
function dfs(u:longint):boolean;
var
v,w:longint;
begin
if flag[u] then exit(false);
flag[u]:=true;
if u=t then exit(true);
w:=list[u];
while w<>0 do
begin
v:=road[w].toit;
if dfs(v) then exit(true);
w:=road[w].next;
end;
flag[u]:=false;
exit(false);
end;
begin
assign(input,'asm_virus.in');assign(output,'asm_virus.out');
reset(input);rewrite(output);
readln(n,q);
for i:=1 to n-1 do
begin
readln(u,v);
add(u,v);
add(v,u);
end;
for i:=1 to q do
begin
read(s,t);
fillchar(flag,sizeof(flag),false);
dfs(s);
read(s,t);
if dfs(s) then writeln('NO')
else writeln('YES');
end;
close(input);close(output);
end.