Vivek and party

HOW TO MAINTAIN THE ORIGINAL ORDERING OF THE INPUT WHILE DOING TOPOLOGICAL SORTING ?
I THINK PRIORITY QUEUE WILL BE USED BUT NOT ABLE TO FIGURE OUT HOW. PLZ HELP.

thanks, figured it out myself