2.14 attend the training in Hangzhou second, the campus is very beautiful!!! Qaq
Duchi in the afternoon for everyone to do the morning three lectures and some CF miscellaneous problems of the selection, which have on the graph to find all ternary ring algorithm. This algorithm is not very complicated, but it's pretty interesting. Qwq
We have a number of integers, recorded as A1,a2,..., an. We want to find out that several of these numbers have a subset of three elements that satisfy the problem, namely {Ai,aj,ak} (Ai,aj) =1 and (Ai,ak) =1 and (Aj,ak) = 1.
The first step is to build the map. The A1,A2,... an is treated as a point numbered,..., N, and if the AI and AJ Coprime, a non-lateral edge is formed between the node I and the node J.
Step two, sort. Sorts the degrees of each node in a certain order (for example, from large to small), then adjusts the non-directed graph to a directed graph based on the resulting sort (for example, the direction of the edge is determined to point from a node with a high degree to a low degree). This will avoid the situation: I->j->k->i. Here's what happens: I->j->k<-i.
The third step, enumeration. First, the node I is identified, enumerating the edges starting from two I, assuming pointing to j,k respectively. If there is an edge between J and K, then the i,j,k constitutes a ternary ring, that is, Ai,aj,ak satisfies the condition of the problem. So the enumeration can be done not heavy not leak oh.
The time complexity of the algorithm can be proved by the case of O ((2m) ^ (3/2)).
Ternary ring: How many elements of a ternary set are found in a number set 22 coprime