Optimized Algorithm for HDTN problem