This problem has been solved by military factions since the late Roman period. The current electronic solution is the 3-way handshake of TCP[1]. If the city cannot be breached through brute force by either military alone then just wait. Each military has access to the outside world for food and resupply while the city starves, so just let the city starve to death and walk in without resistance.
In the early 1860s, just before the Civil War, a US Army Major, Albert Myers[2], solved this problem immediately with a tactical solution: signals. This was first exercised at the First Battle of Bull Run[3] by the confederate army. Though this was not electronic communication it initiated the race towards modern electronic communications in combination with the prior existing telegraph.
So, in consideration for this theoretical thought problem you can solve it by adding more variables, what the military calls METT-TC[4].
In the early 1860s, just before the Civil War, a US Army Major, Albert Myers[2], solved this problem immediately with a tactical solution: signals. This was first exercised at the First Battle of Bull Run[3] by the confederate army. Though this was not electronic communication it initiated the race towards modern electronic communications in combination with the prior existing telegraph.
So, in consideration for this theoretical thought problem you can solve it by adding more variables, what the military calls METT-TC[4].
---
[1] https://www.sciencedirect.com/topics/computer-science/three-...
[2] https://en.wikipedia.org/wiki/Albert_J._Myer
[3] https://en.wikipedia.org/wiki/First_Battle_of_Bull_Run
[4] https://www.trngcmd.marines.mil/Portals/207/Docs/TBS/B2B2367...