Can any one help me why the runtime error occur,seriously tired from the morning

@vijju123 , @ssjgz , @tmwilliamlin , @everule1


#include<bits/stdc++.h>
typedef long long ll;


using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    // code comes here
    
    int t;
    cin>>t;
    
    while(t--)
    {
        int n;
        cin>>n;
        
        int col[n];
        vector<vector<int>> v(n);
        for(int i=0;i<n;i++)
        {
           
            cin>>col[i];
            
            vector<int> temp(col[i]);
            for(int j=0;j<col[i];j++)
            {
                int r;
                cin>>r;
                
                temp.push_back(r);
            }
            
            v.push_back(temp);
        }
        
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<col[i];j++)
            {
                cout<<v[i][j]<<" ";
            }
            cout<<endl;
        }
        cout<<endl;
/*
        int daughter[n],prince[n];
       memset(daughter,0,sizeof(daughter));
       memset(prince,0,sizeof(prince));
       
       for(int i=0;i<n;i++)
       {
           for(int j=0;j<col[i];j++)
           {
               
               if(daughter[i]==0 && 1<=v[i][j] && v[i][j]<=n && prince[v[i][j]-1]==0)
               {
                   daughter[i]=1;
                   prince[v[i][j]-1]=1;
                   break;
               }
           }
       }
       
       int dau=-1,pri=-1;
       for(int i=0;i<n;i++)
       {
           if(daughter[i]==0)
           {
               dau=i+1;
               break;
           }
       }
       
       for(int i=0;i<n;i++)
       {
           if(prince[i]==0)
           {
               pri=i+1;
               break;
           }
       }
       
       if(dau==-1 || pri==-1)
       {
           cout<<"OPTIMAL"<<endl;
       }
       else
       {
           cout<<"IMPROVE"<<endl;
           cout<<dau<<" "<<pri<<endl;
       }
      */  
    }


    return 0;
}

just ignore commented part,do help

1 Like

thanks I really want to know this!!
done Can you help me to figure it out ?
how to resolve such runtime error

What Problem are you trying to solve?

I feel your array size is exceeding memory limit. Array of size > 10^7 are not allowed.

Are you sure about these two lines.
I think push back will increase size of vector instead of filling it up to col[i]

Yes I am sure

there is runtime error I encountered.
I try to solve last codeforces Eductional problem

Yes,I thought that too ,But cant figure it out how to resolve this?

assert (col[i]>= 0);

might help.
It looks like you should write:

cin >> temp[j]; 

instead of:

int r;
cin >> r;
temp.push_back(r);

If you really want to do it, you should start with something like this:

vector<int> temp0(col[i]), temp;
2 Likes

if you want to use push_back then don’t declare the size of the vector initially
eg-
vector < int > arr(n);
arr.push_back(1); //this line will increase the size of the vector from n to n+1 and assign 1 to nth index

I tryied That too,but It is giving same error

okay okay now got it

thanks @tk315