Brute force, and nondeterministic
NestWhile[l \[Function]
If[
FreeQ[VertexDegree@#, 2] \[And]
TreeGraphQ@# \[And]
And @@ Table[\[Not] IsomorphicGraphQ[G, #], {G, l}]
,l~Append~#,l
] &@RandomGraph@{10, 9}
, {}, Length@# < 10 &]
With \[And]
, \[Not]
and \[Function]
counted as one character, I count 149 characters when removing the unnecessary whitespace (all whitespaces).
I swear it worked immediately on my computer :)
Test with Or @@ IsomorphicGraphQ @@@ Subsets[%109, {2}]