Suppose that we have $ n \ge 3$ distinct colours. Let $ f(n)$ be the greatest integer with the property that every side and every diagonal of a convex polygon with $ f(n)$ vertices can be coloured with one of $ n$ colours in the following way:

(i) At least two colours are used,

(ii) any three vertices of the polygon determine either three segments of the same colour or of three different colours.

Show that $ f(n) \le (n\minus{}1)^2$ with equality for infintely many values of $ n$.
1. **Define the problem and notation:**
   We are given \( n \ge 3 \) distinct colors and need to find the greatest integer \( f(n) \) such that every side and diagonal of a convex polygon with \( f(n) \) vertices can be colored with one of \( n \) colors, satisfying:
   - At least two colors are used.
   - Any three vertices of the polygon determine either three segments of the same color or three segments of different colors.

2. **Graph representation:**
   Consider a complete graph \( K_m \) with \( m \) vertices, where \( m = f(n) \). Each edge of this graph represents a side or diagonal of the polygon, and we need to color these edges using \( n \) colors.

3. **Coloring constraints:**
   - At least two colors are used.
   - For any three vertices, the edges connecting them are either all the same color or all different colors.

4. **Prove the upper bound \( f(n) \le (n-1)^2 \):**
   - Assume \( m > (n-1)^2 \).
   - Consider a vertex \( v \) in \( K_m \). It has \( m-1 \) neighbors.
   - By the pigeonhole principle, if \( m-1 > (n-1)^2 \), then there exists a color that is used on more than \( \frac{m-1}{n} \) edges incident to \( v \).
   - Let \( c_1 \) be such a color, and let \( S \) be the set of vertices connected to \( v \) by edges of color \( c_1 \). The size of \( S \) is greater than \( \frac{m-1}{n} \).

5. **Contradiction:**
   - If \( |S| > \frac{m-1}{n} \), then \( |S| > \sqrt{m-1} \) (since \( m-1 > (n-1)^2 \)).
   - Consider another vertex \( u \) connected to \( v \) by a color different from \( c_1 \), say \( c_2 \).
   - The edges between \( u \) and vertices in \( S \) must be colored differently from \( c_1 \) and \( c_2 \), requiring at least \( |S| \) additional colors.
   - This implies \( n \ge 2 + |S| \), but \( |S| > \sqrt{m-1} \), leading to \( n > 2 + \sqrt{m-1} \), which contradicts \( m > (n-1)^2 \).

6. **Equality for infinitely many values of \( n \):**
   - Choose \( n \) such that \( n = k^2 + 1 \) for some integer \( k \).
   - Then \( f(n) = (n-1)^2 = k^4 \).
   - Construct a coloring scheme using \( k^2 + 1 \) colors, ensuring that each vertex is connected to \( k^2 \) vertices with each color exactly \( k-1 \) times.
   - This satisfies the given conditions, proving that \( f(n) = (n-1)^2 \) for these values of \( n \).

\(\blacksquare\)

The final answer is \( \boxed{ f(n) \le (n-1)^2 } \) with equality for infinitely many values of \( n \).