As far as I can think I don't see any method devoid of trial and error "completely", hope to see it
Lets take "m" buffaloes , n cows and 4k(Why!!----total milk produced is 19 , an integer) goats
where "m" "n" and "k" are integers
Try bringing last equation in terms of "k" and any one of "m" and "n"
This is what I got
Now since m<8(Why!! ---milk=40) , its better if you try to put the values till the first time you get an integer ...that's your answer