The present study aims to assess a fully distributed optimal time-varying formation algorithm for a leader-follower system, which is characterized by linear second-order dynamics and operates under a dynamic communication topology with time-varying and uncertain communication weights. In this case, the communication topology's weights may be negative, unlike most other conventional studies where the communication weights should have positive and constant values. Thus, the proposed algorithm resists changes in communication weights. The primary goal of the control strategy is to minimize control effort while ensuring fast convergence to the desired formation. Additionally, the algorithm allows agents to continuously adjust key formation parameters, such as orientation, centroid, and scale, providing flexibility and adaptability during formation. Information about the desired trajectory, rotational velocity, and scale of the formation is given to only one of the directly connected followers through a virtual leader to realize time-varying formation tracking. The designed controller, which is considered fully distributed, can be applied to modern commercial large-scale systems because it does not require information about the eigenvalues of the communication topology. Numerical simulations are implemented to validate the theoretical findings.