II. (50 points) Find all real polynomials $f$ and $g$ such that for all $x \in \mathbf{R}$, we have: $\left(x^{2}+x+1\right) f\left(x^{2}-x+1\right)=$ $\left(x^{2}-x+1\right) g\left(x^{2}+x+1\right)$.
Let $w$ be a non-real cube root of 1, satisfying $w^{2} + w + 1 = 0$, then $g\left(w^{2} + w + 1\right) g(0) = 0$. Let $\alpha$ be a non-real cube root of -1, then $f\left(\alpha^{2} - \alpha + 1\right) = f(0) = 0$. Therefore, we can set: $f(x) = x \cdot a(x) ; g(x) = x \cdot b(x)$.

Thus, the original condition can be transformed into: $a\left(x^{2} - x + 1\right) = b\left(x^{2} + x + 1\right)$. Let $x = -y$, we get: $a\left(y^{2} + y + 1\right) = b\left(y^{2} - y + 1\right)$,

then: $b\left(x^{2} + x + 1\right) = b\left[(x + 1)^{2} - (x + 1) + 1\right] = a\left[(x + 1)^{2} + (x + 1) + 1\right]$.
Hence, $a\left(x^{2} - x + 1\right) = a\left[(x + 1)^{2} + (x + 1) + 1\right]$.
We will prove that there are infinitely many $n$ such that: $a\left(n^{2} + 3n + 3\right) = a(1)$. For $n = 1$, we have: $a(1) = a(7)$. Assume $a\left[(n-1)^{2} + 3(n-1) + 3\right] = a(1) (n \geqslant 2)$, then $a\left[(n+1)^{2} + 3(n + 1) + 3\right] = a\left[(n+2)^{2} + (n+2) + 1\right] = a\left[(n+1)^{2} - (n + 1) + 1\right] = a\left[(n-1)^{2} + 3(n-1) + 3\right] = a(1)$. Since the polynomial $a(x) - a(1)$ has infinitely many roots, $a(x) - a(1)$ is the zero polynomial, i.e., $a(x)$ is a constant, thus $f(x) = kx$. Similarly, we can conclude: $g(x) = kx$.