Spatially homogeneous elemental distributions in vapor-liquid-solid or catalyst-free III-V ternary nanowires based on group III intermix is the exception rather than the rule. Herein, we develop the nanowire growth theory by combining the material transport equations and the minimum energy principle for the liquid-solid or vapor-solid growth on the top facet of III-V ternary nanowires AxB1-xC. These considerations lead to a general vapor-solid distribution whose governing parameters depend on the nanowire length and radius due to surface diffusion of group III adatoms. We reveal the two competing effects on the vapor-solid distribution. One effect is related to different diffusion lengths of group III adatoms A and B, and it favors incorporation of an element A with a longer diffusion length (for example, In in InxGa1-xAs or Ga in AlxGa1-xAs) toward the nanowire top. The other effect originates from gradually decreasing the effective V/III ratio of fluxes entering a catalyst droplet, and it favors near-equilibrium vapor-solid distributions. Length-dependent surface diffusion of group III adatoms decreases the effective V/III ratios in nanowires based on group III intermix and increases it in nanowires based on group V intermix. Consequently, the compositional trends in such nanowires are very different. The model fits well a wide range of data on the elemental distributions in InxGa1-xAs, Al1-xGaxAs and In1-xSbxAs nanowires. The simple analytic vapor-solid distribution may be used for the compositional tuning of different nanowires. The concept of a single ternary nucleus forming at the minimum free energy for a given size generalizes the earlier models of the nucleation-limited composition, and it may be useful in the compositional modeling of a wide range of nanostructures.