added tarjan and better version for previous