Algorithm design and implementation of critical path (C language)