An index formula for simple graphs