资源预览内容
第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
第9页 / 共10页
第10页 / 共10页
亲,该文档总共10页全部预览完了,如果喜欢就下载吧!
资源描述
切割树 treecut -题意简述 有一个N个节点的无根树,各节点编号为 1N,现在要求你删除其中的一个点,使分 割开的连通块中节点个数都不超过原来的 一半。 数据范围 1 0 do begin a:=pp1.v; /相邻点 if c a =0 then begin / if 没有访 问过的 c a :=dfs( a ); /递归 . end; p1:=pp1.next; /取链表下一个 节点 end; end;切割树 treecut -参考程序 function dfs( root : integer) :integer; begin . while p1 N div 2 then okroot:=false; /a分支节点 过多 inc(croot, c a ); end; p1:=pp1.next; /取链表下一个节点 end; if ( N - croot N div 2 ) then okroot :=false; /向上分 支判断 dfs := croot; end;切割树 treecut -参考程序 begin assign(input, treecut.in); reset(input); assign(output,treecut.out); rewrite(output); init; dfs(1); a:=0; for i:=1 to N do if oki then begin writeln(i); inc(a); end; if a=0 then writeln(NONE); close(output); close(input); end.
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号