1142 Maximal Clique(25 分)

#include
#include
using namespace std;
int nv, ne;
const int maxn = 210;
mapmp;
bool vis[maxn];
bool isnot(int v, int num[],int n)
{
    for (int i = 0; i < n; i++)
    {
        if (v == num[i])return false;
    }
    return true;
}
int main()
{
    scanf("%d%d", &nv, &ne);
    while (ne--)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        mp[x * 1000 + y] = mp[y * 1000 + x] = true;
    }
    int k;
    scanf("%d", &k);
    while (k--)
    {
        bool minclique = false;
        int m, num[maxn];
        scanf("%d", &m);
        for (int i = 0; i < m; i++)scanf("%d", &num[i]);
        int cnt = 0;
        for (int i = 0; i < m; i++)
        {
            for (int j = i + 1; j < m; j++)
            {
                if (mp[num[i] * 1000 + num[j]] == true)cnt++;
            }
        }
        if (cnt == (m*(m-1)) / 2)minclique = true;
        else minclique = false;
        bool maxclique = true;
        for (int i = 1; i <= nv; i++)
        {
            if (isnot(i, num,m))
            {
                int tempcnt = 0;
                for (int j = 0; j < m; j++)
                {
                    if (mp[i * 1000 + num[j]] == true)tempcnt++;
                }
                if (cnt + tempcnt == (m + 1)*m / 2)
                {
                    maxclique = false;
                    break;
                }
            }
        }
        if (minclique == false)printf("Not a Clique\n");
        else if (minclique == true && maxclique == false)printf("Not Maximal\n");
        else if (minclique == true && maxclique == true)printf("Yes\n");
    }
    return 0;
}

你可能感兴趣的:(1142 Maximal Clique(25 分))