A data structure for dynamic trees