记录编号 394317 评测结果 AAAAAAAAAA
题目名称 文理分班 最终得分 100
用户昵称 GravatarHallmeow 是否通过 通过
代码语言 C++ 运行时间 2.558 s
提交时间 2017-04-13 10:36:57 内存使用 48.04 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 2500
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
int match[N];
int flag[N],rela[N][N],a[N][N];
int t,n;
int liu[N],go[N];
int jiliu,jigo;
int cun[N];
bool find(int p)
{
     pos(i,1,jigo)
     {
        if(a[p][i]==1&&flag[i]==0)
        {
           flag[i]=1;
           if(match[i]==0||find(match[i]))
           {
             match[i]=p;
             return true;
           }
        }
     }
     return false;
}
void del()
{
     memset(liu,0,sizeof(liu));
     memset(go,0,sizeof(go));
     memset(match,0,sizeof(match));
     memset(a,0,sizeof(a));
     memset(flag,0,sizeof(flag));
     memset(cun,0,sizeof(cun));
     memset(rela,0,sizeof(rela));
     jiliu=0;jigo=0;
}
int main()
{
    freopen("divideb.in","r",stdin);
    freopen("divideb.out","w",stdout);
    cin>>t;
    while(t--)
    {
       del();
       cin>>n;
       pos(i,1,n)
       {
           int x;
           cin>>x;
           if(x==0)
             liu[++jiliu]=i;
           if(x==1)
             cun[i]=1;
       }
       pos(i,1,n)
       {
           int x;
           cin>>x;
           if(cun[i]==1)
           {
              if(x==0)
              {
                liu[++jiliu]=i;
                go[++jigo]=i;
              }
              if(x==1)
                go[++jigo]=i;
           }
       }
       pos(i,1,n)
         pos(j,1,n)
         {
            cin>>rela[i][j];
            if(i==j)
              rela[i][j]=1;
         }
       pos(i,1,jiliu)
         pos(j,1,jigo)
         {
            if(rela[liu[i]][go[j]]==1)
               a[i][j]=1;
         }
       int ans=0;
       pos(i,1,jiliu)
       {
              memset(flag,0,sizeof(flag));
              if(find(i))
                ans++;
       }
       //cout<<"jiliu="<<jiliu<<"   jigo="<<jigo<<endl;
       if(ans==jiliu)
         cout<<"^_^"<<endl;
       else
         cout<<"T_T"<<endl;
    }
    //while(1);
    return 0;
}