如果在这个团队中村取出三个或三个以上的人来,如果他们互相为朋友,或者互相不是朋友那么这个团队是一个bad team,反之则为great team 。可以根据鸽巢原理,也就是用类似并查集的方法去找大小为3的环,如果1 和 2 是朋友我们只需要判断下 他们两个的朋友集合是否存在交集。这里我们用bitset来储存朋友信息,先预处理储存每个人的朋友信息,然后两两遍历,便利时将 i,和j+i 这两个 bitset &一下,找到交集,如果集合中含有大于等于一个 1就可以让整个团队为bad team。因为互相为朋友和互相不为朋友其实是镜像关系,所以可以用相同的方法处理。
ACcode
//C - Friend-Graph HDU - 6152
#include <iostream>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<unordered_map>
#define int long long
#define endl '\n'
#define lowbit(x) (x &-x)
#define mh(x) memset(x, -1, sizeof h)
#define debug(x) cerr << #x << "=" << x << endl;
#define brk exit(0);
using namespace std;
void TLE() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
const int N = 3e3 + 10;
const int M = 2 * N;
const int mod = 998244353;
const double esp = 1e-6;
const double pi = acos(-1);
typedef pair<int, int> PII;
typedef long long ll;
bitset<3001>g[N], f[N], init;
bool tt[N][N];
void solve()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
g[i] = init, f[i] = init;
for (int i = 1;i < n;i++)
{
for (int j = 1;j <= n - i;j++)
{
int x;
cin >> x;tt[i][j] = x;
if (x == 1)
g[i][j + i] = 1, g[j + i][i] = 1;
else if (x == 0)
f[i][j + i] = 1, f[j + i][i] = 1;
}
}
for (int i = 1;i < n;i++)
{
for (int j = 1;j <= n - i;j++)
{
if (tt[i][j] == 1)
{
bitset<3001>res = (g[i] & g[j + i]);
if (res.count() >= 1)
{
cout << "Bad Team!" << endl;
return;
}
}
else
{
bitset<3001>res = (g[i] & g[j + i]);
res = (f[i] & f[j + i]);
if (res.count() >= 1)
{
cout << "Bad Team!" << endl;
return;
}
}
}
}
cout << "Great Team!" << endl;
}
signed main()
{
TLE();
int T;cin >> T;
while (T--)
solve();
return 0;
}