# Finding all “bad” triangles in a full-simple-graph

Let $G = \left\langle {V,E} \right\rangle$, a simple and complete graph with the size of $n$.

Each edge in the graph can be colored with blue or red.
A "bad" triangle defined to be a triangle (circle with three edges) such that it contains two colors (two blue edges and one red and vice-verca).

Also, $d_i$ is the number for blue edges for the vertex $i$.

It appears that the number of bad triangles defined by the following formula which I'm trying to understand:

$$\sum\limits_{i = 1}^n {\frac{{({d_i} \cdot (n - 1 - {d_i}))}}{2}}$$

Trying to interpret it:
for each vertex, the number of bad triangles is the number of blue edges multiplied by the number of red edges divided by $2$.

But what is standing behind this?

Since the graph is complete, all edges are present. Thus, if we find a red and a blue edge with endpoints at a vertex $A$, we know the triangle with those two edges and the third edge joining them must have at least two colors. For every vertex, we can calculate the number of bad triangles found in this way by multiplying the number of red and blue edges of the vertex. We count every triangle twice now, because every bad triangle has two points where two edges of different color meet. Therefore, we need to divide the number of bad triangles we found by two, yielding $$\frac 12 \sum_{v\in V}d_v(n-1-d_v)=\sum_{i=1}^n\frac{d_i(n-1-d_i)}2$$ (We take $n-1-d_i$ instead of $n-d_i$, because there are $n-1$ points different from $v\in V$, and thus also $n-1$ edges joining $v$.)
Every pair of one blue and one red edge joining at a vertex can make exactly one bad triangle, because we can just join the endpoints of those two edges. We can choose one blue edge in $d_i$ ways. We can choose one red edge in $n-1-d_i$ ways. Together, this gives $d_i(n-1-d_i)$ ways to choose one blue and one red edge.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8692041,"math_prob":0.9993086,"size":721,"snap":"2019-26-2019-30","text_gpt3_token_len":194,"char_repetition_ratio":0.15062761,"word_repetition_ratio":0.016,"special_character_ratio":0.2815534,"punctuation_ratio":0.08275862,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":1.000004,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-17T05:01:17Z\",\"WARC-Record-ID\":\"<urn:uuid:77f32dc8-0460-4bee-bab7-471c0873604b>\",\"Content-Length\":\"139100\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bbe89b44-7075-42ad-a657-6a9161ff9178>\",\"WARC-Concurrent-To\":\"<urn:uuid:e1c7f8d7-b4db-4a94-947d-0559bfa17bdd>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://math.stackexchange.com/questions/666030/finding-all-bad-triangles-in-a-full-simple-graph\",\"WARC-Payload-Digest\":\"sha1:OIJTI7CPI7P2OM5GKAZVKXHDYYLW4HYD\",\"WARC-Block-Digest\":\"sha1:MEBFLB2S674W4GIGG3ANFOBFYTPEGYL3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195525046.5_warc_CC-MAIN-20190717041500-20190717063500-00550.warc.gz\"}"}