美文网首页
1142 Maximal Clique (25分)

1142 Maximal Clique (25分)

作者: zjh3029 | 来源:发表于2018-08-09 17:35 被阅读0次
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include<map>
    using namespace std;
    
    int M, N, L,K,a,b,c;
    vector<vector<int> > v;
    vector<int> vm;
    int main()
    {
        cin >> N>>M;
        v.resize(N);
    
        for (int i = 0; i < v.size(); i++)
        {
            v[i].resize(N);
        }
        for (int i = 0; i < M; i++)
        {
            cin >> a >> b;
            v[a - 1][b - 1] = v[b - 1][a - 1] = 1;
        }
        bool flag = false;
        cin >> L;
        for (int i = 0; i < L; i++)
        {//每轮循环
            cin >> K;
            flag = false;
            vm.clear();
            int j = 0;
            for (; j < K; j++)
            {//每行输入
                cin >> c;
                for (auto d : vm)
                {
                    if (v[d][c-1]!=1)
                    {//不符合条件
                        while (cin.get() != '\n') continue;
                        flag = true;
                        break;
                    }
                }
                vm.push_back(c - 1);
                if (flag==true)
                {
                    cout << "Not a Clique" << endl;
                    break;
                }
            }
            int cnt2 = 0;
            bool flag2 = false;
            if(j==K&& flag==false)
            {
                for (auto f : vm) 
                {
                    flag2 == false;
                    for (int i = 0; i < N; i++)
                    {
                        cnt2 = 0;
                        if (v[f][i] == 1)
                        {
                            for (auto h : vm)
                            {
                                if (v[i][h] == 1)
                                {
                                    cnt2++;
                                }
                            }
                            if (cnt2==vm.size())
                            {
                                cout << "Not Maximal" << endl;
                                cnt2 = 0;
                                flag2 = true;
                                break;
                            }
                        }
                    }
                    if (flag2 == true)
                    {
                        break;
                    }
                }
                if (flag2 == false)
                {
                    cout << "Yes" << endl;
                }
            }
        }
    
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:1142 Maximal Clique (25分)

          本文链接:https://www.haomeiwen.com/subject/twzqbftx.html