Optimization in my beautiful vertices implementation

Please somebody help me understand why I am getting TLE in this.