try using if(mst[x]==true){continue;} in this starting of the last while loop
try using if(mst[x]==true){continue;}
in this starting of the last while loop