| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA了..用链表+树状数组..恳求大牛给数据!或者帮忙查查错...type
enode=^xx;
xx=record
b:longint;
next:enode;
end;
const
maxn=100000;
var
n,m,dep:longint;
c:array[1..maxn] of longint;
t:array[1..maxn] of boolean;
node:array[1..maxn,1..2] of longint;
a,root:array[1..maxn] of enode;
procedure init;
var
i,j,x,y:longint;
p:enode;
begin
readln(n);
for i:=1 to n do root[i]:=nil;
for i:=1 to n-1 do
begin
readln(x,y);
new(p);
p^.b:=y;
if a[x]=nil then
begin
a[x]:=p;
root[x]:=a[x];
end
else
begin
a[x]^.next:=p;
a[x]:=p;
end;
end;
end;
procedure dfs(x:longint;var min:longint);
var
te,te2:longint; i:enode;
begin
te:=min; te2:=te;
i:=root[x];
while i<>nil do
begin
dfs(i^.b,te);
if te<min then min:=te;
te:=te2;
i:=i^.next;
end;
inc(dep);
node[x,1]:=dep;
if dep<min then min:=dep;
node[x,2]:=min;
end;
procedure main;
var
i,x:longint;
ch:char;
function f(x:longint):longint;
begin
exit(x and (-x));
end;
function sum(x:longint):longint;
begin
sum:=0;
while x>0 do
begin
sum:=sum+c[x];
dec(x,f(x));
end;
end;
procedure change(i,x:longint);
begin
while i<=maxn do
begin
inc(c[i],x);
inc(i,f(i));
end;
end;
begin
x:=n;
dfs(1,x);
for i:=1 to n do
change(i,1);
readln(m);
for i:=1 to m do
begin
read(ch); readln(x);
if ch='Q' then writeln(sum(node[x,1])-sum(node[x,2]-1))
else
begin
if t[x] then change(x,1) else change(x,-1);
t[x]:=not t[x];
end;
end;
end;
begin
init;
main;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator