Need help to understand solution to The Great Revegetation

In the solution to the problem The Great Revegetation why do we do if (B[j] == i && G[A[j]] == g) ok = false; instead of if ((a[j] == i || b[j] == i) && grass[a[j]] == color)?

#include <iostream>
#include <fstream>
using namespace std;
 
int main(void)
{
  int N, M;
  int A[151], B[151], G[101];
  ifstream fin ("revegetate.in");
  fin >> N >> M;
  for (int i=0; i<M; i++) { 
    fin >> A[i] >> B[i];
    if (A[i] > B[i]) swap (A[i], B[i]);
  }
 
  ofstream fout ("revegetate.out");  
  for (int i=1; i<=N; i++) {
    int g;
    for (g = 1; g <= 4; g++) {
      bool ok = true;
      for (int j=0; j<M; j++) 
	if (B[j] == i && G[A[j]] == g) ok = false; // <-- I am talking about this line
      if (ok) break;
    }
    G[i] = g;
    fout << g;
  }
  fout << "\n";
  return 0;
}

http://www.usaco.org/index.php?page=viewproblem2&cpid=916

Why do you think it should be your if statement?