--
-- find the center of a free tree
--
program treecenter ;
read ( e ) ; -- tree e is a symmetric edge relation
print ( e ) ;
S := domain e; -- S is the set of vertices
while # S > 2 loop--repeatedly remove leaves until 1 or 2 vertices remain
S - := { x in S | # ( e { x } * S ) = 1 } ;
end loop ;
print ( S ) ; -- final value of S is the center
end ;