WHY my code is not working for multiple test case ?while(test--)

My code gives right answer for every test case put individually but when I use while(test–) for all test cases ,it starts giving Wrong answers.

Problem :https://codeforces.com/problemset/problem/1327/B

I have used while(test–) and there is no global variable used.

#include <iostream>
using namespace std;
#include<bits/stdc++.h>

int main() 
{

int t;
cin>>t;
while(t--)
{
    
    int size,n;
    unordered_map<int,bool>rishta;
    unordered_map<int,bool>confirm;

    cin>>n;
   for(int i=1;i<=n;i++)
    {
        cin>>size;
        
     int input;
        for(int j=0;j<size;j++)
        {
            
            cin>>input;
            
            if(rishta[input])
            {
                
                continue;
            }
            else
            
            {
                rishta[input]=true;
                confirm[i]=true;
                break;
                
            }
            
            
            
            
            
        }
        
        
        
     }
         int x = -1,y = -1;
     
    
    for(int k=1;k<=n;k++)
    {
        if(!confirm[k])
        {
          y=k;
          break;
            
        }
        
        
    }
    
 for(int k=1;k<=n;k++)
    {
        if(!rishta[k])
        {
            x = k;
            break;
            
        }
        
        
    }
    
    
    
    if(x!=-1 && y!=-1)
    {
        cout<<"IMPROVE"<<endl;
        cout<<x<<" "<<y<<endl;
    }
    
    else
    {
        
        cout<<"OPTIMAL"<<endl;
        
               
         
     }
    
    
}



}

You’re not reading all the input correctly due to the break on line 38.

2 Likes

But ,I dont want to take all the input ,when I get an input not recorded in map yet then i will add it to the map as true and break it as I want only the first unvisited occurence of the input .

Then you’re not reading subsequent input in the format it’s intended to be read in i.e. you’re reading it wrongly :man_shrugging:

2 Likes

You can also check it for single test case >>ie it working fine .
1
4
2 2 3
2 1 2
2 3 4
1 3

sorry ,yes you are right ,i messed it up

1 Like

There’s some handy tips for avoiding this sort of thing, here:

(read the whole thread).

In particular:

Simply printing out the value of n after reading it would have revealed the flaw.

1 Like