Planning Optimal Paths for Multi-agent Systems on Graphs