Hiding Menu Links Based on URL
If you want to have page specific menu system, you can create different menu blocks and put them appropriately.

Considering your example

Main menu is nothing but a menu block, so instead of using main menu block you can have two different menu blocks let say Menu block A and Menu block B

So in block configuration for Menu block A you will put the block visibility to show on "undergraduate" only and similarly put for Menu block b put it as "graduate"

Remember to put the menu blocks in same region as your main menu. You are just toggling menu block visibility on basis of URL.