node=record
data:longint;
a:re;
end;
var tree:array [0..1000000] of node;
father:array [0..3000] of longint;
x,y:string;fx,fy:longint;
count:longint;
n,m,p,tot:longint;
function getfather(v:longint):longint;
begin
if father[v]=v then exit(v);
father[v]:=getfather(father[v]);
exit(father[v]);
end;
function change(st:string):longint;
var i,t,p:longint;
begin
t:=1;
for i:=1 to length(st) do
begin
p:=ord(st[i])-ord('A');
if tree[t].a[p]<>-1 then
begin
t:=tree[t].a[p];
end
else
begin
inc(tot);
tree[t].a[p]:=tot;
t:=tot;
end;
end;
if (tree[t].data<>-1) then exit(tree[t].data)
else
begin
inc(count);
tree[t].data:=count;
exit(count);
end;
end;
procedure init;
var k,i:longint; s:string;
begin
fillchar(tree,sizeof(tree),255);
readln(n,m,p);
for i:=1 to n do
begin
readln(s);
k:=change(s);
end;
for i:=1 to n do
father[i]:=i;
for i:=1 to m do
begin
readln(s);
k:=pos(' ',s);
x:=copy(s,1,k-1);
y:=copy(s,k+1,length(s)-k);
fx:=getfather(change(x));
fy:=getfather(change(y));
father[fx]:=fy;
end;
end;
procedure work;
var i,k:longint;s:string;
begin
for i:=1 to p do
begin
readln(s);
k:=pos(' ',s);
x:=copy(s,1,k-1);
y:=copy(s,k+1,length(s)-k);
fx:=getfather(change(x));
fy:=getfather(change(y));
if fx=fy then
writeln('safe')
else
writeln('cc cry');
end;
end;
begin
init;
work;
end.
并察集+字典树,8和10过不了。8有一个点,10有16个点,都是实际没关系,我输出有关系。求错误。