Graph Theory

Answer & solution
Official answer: D
The ith diagonal entry of A³ counts length-three closed walks starting at vertex i. In a simple undirected graph each such walk traverses a triangle. Each triangle contributes three starting vertices and two directions, hence six walks. Therefore the number of triangles is trace(A³)/6, D.
A length-three closed walk i→j→k→i cannot repeat an adjacent vertex because there are no loops, so i,j,k are distinct. Every triangle is counted starting at i,j,k and in each of two orientations: 3×2=6. Dividing by 3 alone would still count both orientations.