There can be only two cases when the given condition (adjacent vertices receive distinct colours) will satisfy:
Case 1: All vertices having different colors. Basically in this Case we need four different colors.
Number of ways to do that is -----> r(r-1)(r-2)(r-3)
Case 2: vertex b and d having same color, but other vertices(a and c) having different colors than b/d and also colors of a and c are different. So, basically in this Case we need three different colors(one color for a, another different color for c and another different color for b/d) . Number of ways to do that is -----> r(r-1)(r-2)
So in total (Case 1 +Case 2) Number of ways are ---> r(r-1)(r-2)(r-3) + r(r-1)(r-2) = r(r-1)(r-2) [(r-3) +1] = r(r-1) (r-2)^2
= (r^2 -r) (r^2 -4r + 4) = r^4−5r^3+8r^2−4r
Another Simple way of thinking:
Since a,d,c vertices form a triangle(hence adjacent to each other) so, they have to be colored using there different colors.
So, a,d,c vertices can be colored in r * (r-1)* (r-2) ways. Now for b vertex we are left with r-2 choices (because b vertex can't be colored same as vertex a or c). So, a,d,c,b vertices can be colored in r * (r-1)* (r-2) * (r-2) ways such that no adjacent vertices gets same color. r * (r-1)* (r-2) * (r-2)= r^4−5r^3+8r^2−4r