Fork Copy #include using namespace std; int T,tc; int n, m; int gender[100001]; int initColor[100001]; int color[100001]; int edges[100000][2]; int adjVertex[100001]; int **adj; int queue[100001]; int head, tail; int vs[100001]; int minInservion; int canAssignColor(int student, int c){ for (int i=1;i<=adj[student][0];i++){ if (color[adj[student][i]]==c) return false; } return true; } int solution(){ for (int i=1;i<=n;i++) vs[i]=0; head=0; tail=0; queue[0]=1; vs[1]=1; color[1]=0; while (head<=tail){ int tstudent=queue[head++]; int tcolor=color[tstudent]; // cout<<"top "<>T; for (tc=1;tc<=T;tc++){ cin>>n>>m; adj=new int*[n+1]; for (int i=1;i<=n;i++){ adjVertex[i]=0; color[i]=-1; // read gender char c; cin>>c; if (c=='B') gender[i]=0; else if (c=='G') gender[i]=1; // cout<>edges[i][0]>>edges[i][1]; adjVertex[edges[i][0]]++; adjVertex[edges[i][1]]++; } // allocate memory for (int i=1;i<=n;i++){ adj[i]=new int[adjVertex[i]+1]; adj[i][0]=0; } // assign adj list int tmp1, tmp2; for (int i=0;i