Help needed in finding error in my code

Revision en1, by qwertsboy1234, 2021-04-11 08:32:47

Here is a codechef problem Friends. Here is my solution ,its giving wrong answer.Can anybody help me find out the error.

#include<bits/stdc++.h>
using namespace std;
#define dd double
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define pr pair<ll,ll>
#define pri pair<pr,ll>
#define pir pair<ll,pr>
#define ppr pair<pr,pr>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll INF=1e18;
ll mod=1e9+7;
int main()
{
   #ifndef ONLINE_JUDGE
   freopen("inp.txt","r",stdin);
   freopen("otpt.txt","w",stdout);
   #endif
   fastio;
   ll te=1;
   while(te--)
   {
       ll n,i,j,t;
       cin>>n;
       vector<vector<char> > v1(n,vector<char>(n));
       for(i=0;i<n;i++)
       {
         for(j=0;j<n;j++)
         {
            cin>>v1[i][j];
         }
       }
       ll ans=0;
       queue<pr> q;
       for(i=0;i<n;i++)
       {
         for(j=i+1;j<n;j++)
         {
            if(v1[i][j]=='0')
            {
               q.push(mp(i,j));
            }
         }
       }
       q.push(mp(-1ll,-1ll));
       ll last=q.size();
       ll ct=0;
       while(1)
       {
          ct++;
          pr p=q.front();
          q.pop();
          if(p.fi==-1)
          {
            if(last==q.size()||q.empty())
            {
               break;
            }
            last=q.size();
            q.push(p);
            continue;
          }
          ll i=p.fi,j=p.sc;
          for(t=0;t<n;t++)
          {
            if(v1[t][i]=='1'&&v1[t][j]=='1'&&t!=i&&t!=j)
            {
               break;
            }
          }
          if(t==n)
          {
            q.push(p);
            continue;
          }
          if(v1[i][j]!='1')
          {
               ans+=1;
          }
          v1[j][i]='1';
          v1[i][j]='1';
       }
       cout<<2*ans<<endl;
   } 
}

Thanks in advance.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English qwertsboy1234 2021-04-11 08:32:47 2079 Initial revision (published)