for first graph
case 1: now first calculate ending with 0
is same as ending with 10 (because 1 will come after 4,5,2,3 so its position should be just before 0)
now 4,5,2,3 can be arrange in 4!/3!=4 .........................here 3! because we have to maintain the sequence of 5,2,3
case 2: now calculate ending with 1
starting with 54 is 3!/2!=3
starting with 45 is 3!/2!=3
starting with 52 is 3!/2!=3
so total is 3+3+3=9
grand total 4+9=13