I ran into the same issue and after digging around, I wasn’t able to find any good solutions. So, I wrote my own. Basically it’s a short function that you give the category ID to. It’ll then go all the way up the category chain and return to you the root parent category ID.
If it’s of any help, you can get it at https://www.yash-patel.com/yfactor/2008/12/25/getting-the-top-level-parent
I hope that helps!
Yash.