A graph-theoretic approach to multitasking