Help in Problem INDEP -Feb Luchtime

My code is giving WAs in few test cases, can someone help in finding the failing test cases and the bug.

Problem:INDEP Problem - CodeChef

#include <iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t;
    cin>>t;
    while(t--)
    {
        
        ll m,n,x,y,ans=0;
        cin>>n>>m;
        vector<int>edges[n];
        map<vector<int>,int>freq;
     for(int i=0;i<m;i++)
     {
           cin>>x>>y;
           x--;
           y--;
           edges[x].push_back(y);
           edges[y].push_back(x);
     }
      for(int i=0;i<n;i++)
     {
      sort(edges[i].begin(),edges[i].end());  
     }
     
        for(int i=0;i<n;i++)
     {
           freq[edges[i]]++;
     }
      
      string a(n,'1');
     
     for(auto it:freq)
     {
          vector<int>temp = it.first;
          if(temp.size()+it.second==n  )
         {
               ans++;
         }
         
         if(ans==1)
         {
             for(int i=0;i<temp.size();i++)
             {
                   a[temp[i]]='0';
             }
         }
    
           
     }
     
if(ans==0)
{
     a=string(n,'0');
}
 
    cout<<ans<<"\n";
    cout<<a<<"\n";
                

}
    
}
if(temp.size()+it.second==n  )
         {
               ans++;
         }
         
         if(ans==1)
         {
             for(int i=0;i<temp.size();i++)
             {
                   a[temp[i]]='0';
             }
         }

This part of your code.

1 Like

can you please elaborate the problem??

After you find the first good partition (if any), your output changes until you find the second good partition (if any).

1 Like

Bro I cannot still understand, when the partition is found I am increasing ans var by 1, that’s what we are supposed to do, how the output will change ???

Say you found a good partition for the first time, your count will be 1. Your a array will change.
Next time you find a bad partition, you count is still 1 and a array will change again which wasn’t supposed to change.

1 Like

understood , thank you!!!

1 Like