1142. Maximal Clique (25) 19‘

简介: #include #include #include #include #include using namespace std;int e[201][201];vector temp;bool judge(){ int flag = 1; for(int i = 0; i < temp.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int e[201][201];
vector<int> temp;

bool judge(){
    int flag = 1;
    for(int i = 0; i < temp.size(); i++){
        for(int j = i + 1; j < temp.size(); j++){
            if(!e[temp[i]][temp[j]]){
                flag = 0;
                break;
            }
        }
    }
    return flag;
}

int main( )
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        e[a][b] = e[b][a] = 1;
    }


    int k;
    cin >> k;
    for(int i = 0; i < k; i++){
        int c;
        cin >> c;
        temp.clear();
        vector<bool> book(n+1);
        for(int j = 0; j < c; j++){
            int t;
            cin >> t;
            book[t] = true;
            temp.push_back(t);
        }
        int flag = 1;
        if(c == 1){ printf("Yes\n"); continue;}
        if(judge()){
            for(int i = 1; i <= n; i++){
                if(!book[i]){
                    temp.push_back(i);
                    if(judge()){
                        flag = 0;
                        break;
                    }
                    temp.pop_back();
                }
            }
            if(flag){
                printf("Yes\n");
            }else{
                printf("Not Maximal\n");
            }
        }else{
            printf("Not a Clique\n");
        }

    }

    return 0;
}
目录
相关文章
UVa11714 - Blind Sorting
UVa11714 - Blind Sorting
55 0
|
机器学习/深度学习
1257:Knight Moves 2021-01-09
1257:Knight Moves 2021-01-09
|
算法
LeetCode 300. Longest Increasing Subsequence
给定一个无序的整数数组,找到其中最长上升子序列的长度。
56 0
LeetCode 300. Longest Increasing Subsequence
|
算法
LeetCode 334. Increasing Triplet Subsequence
给定一个未排序的数组,判断这个数组中是否存在长度为 3 的递增子序列。 数学表达式如下: 如果存在这样的 i, j, k, 且满足 0 ≤ i < j < k ≤ n-1, 使得 arr[i] < arr[j] < arr[k] ,返回 true ; 否则返回 false 。
97 0
LeetCode 334. Increasing Triplet Subsequence
UVA699 下落的树叶 The Falling Leaves
UVA699 下落的树叶 The Falling Leaves
UVA699 下落的树叶 The Falling Leaves
【LeetCode】Increasing Triplet Subsequence(334)
  Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
104 0
【1096】Consecutive Factors (20 分)
【1096】Consecutive Factors (20 分) 【1096】Consecutive Factors (20 分)
132 0
|
算法 C#
算法题丨Longest Consecutive Sequence
描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
1122 0

热门文章

最新文章