I hope you find these two resources useful to address your question. I'm also pretty integrated about the possible answers, but I definitely bet on doing it using graphs. I'm preparing a detailed and concrete explanation on why I guess this conclusion but that one will need to wait for now!
For now as I have already told you, check out these ones.