Maximum profit on a undirected tree

Can anybody optimize this problem ?