Treewidth-based algorithms for the small parsimony problem on networks