# Getting WA for Fill the matrix

https://www.codechef.com/LRNDSA08/problems/FILLMTR

``````    #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<vector<ll>> edges;
ll parent[100100], nrank[100100];
ll color[100100];

ll findSet(ll v){
if(v==parent[v]){
return v;
}
parent[v] = findSet(parent[v]);
return parent[v];
}

void unionSet(ll u,ll v){
ll pu = findSet(u);
ll pv = findSet(v);
if(pu!=pv){
if(nrank[pu]>nrank[pv]){
ll temp = pv;
pv=pu;
pu=temp;
}
parent[pu]=pv;
if(nrank[pu]==nrank[pv]){
nrank[pv]++;
}
}
}

bool checkcycle(ll N){
for(ll i=0;i<N;i++){
color[i]=-1;
}

for(ll i=0;i<edges.size();i++){
ll u = edges[i][0];
ll v = edges[i][1];
u = findSet(u);
v = findSet(v);
if(u==v){
return true;
}
if(color[u]==-1 && color[v]==-1){
color[u]=0;
color[v]=1;
}else if (color[u]==-1 && color[v]!=-1){
color[u]=!color[v];
}else if(color[v]==-1 && color[u]!=-1){
color[v]=!color[u];
}else if(color[v]==color[u]){
return true;
}
}
return false;
}

int main() {
fastio
ll T;
cin>>T;
while(T--){
ll N,Q;
cin>>N>>Q;
for(ll i=0;i<N;i++){
edges.clear();
parent[i]=i;
nrank[i]=0;
}
while (Q--){
ll i,j,v;
cin>>i>>j>>v;
if(v){
edges.push_back({i,j});
}else{
unionSet(i,j);
}
}
if(checkcycle(N)){
cout<<"no"<<"\n";
}else{
cout<<"yes"<<"\n";
}
}
return 0;
}
``````

please someone help me to get AC

1
3 3
1 2 1
2 1 3
3 3 0

Should give no, yours will give yes!
You are not checking if edge between same vertices have consistent weights.

weight can only be 1 or 0