contestada

I am curious about why kingdom of Bavaria was assimilated by Prussia instead of Austria-Hungary
If I consider following facts in 1854
then something happened and in 1871 Bavaria joins Germany forever. Why?