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;
}
目录
相关文章
|
7月前
|
C++
hackerrank challenges median
只能说这题我想多了,使用普通的插入排序完全可以解决这道题,在查找的时候用二分加快查找速度。 正确解题报告 这道题的关键在于,不能用int,因为两个int相加可能会越界!因为这个WA了好多遍。所以改用long long。 对double,使用math.h中的函数ceil(double)可以取整,根据ceil(v) == v的结果可以判断v是否是整数。
28 0
|
10月前
|
机器学习/深度学习
1257:Knight Moves 2021-01-09
1257:Knight Moves 2021-01-09
|
算法
LeetCode 334. Increasing Triplet Subsequence
给定一个未排序的数组,判断这个数组中是否存在长度为 3 的递增子序列。 数学表达式如下: 如果存在这样的 i, j, k, 且满足 0 ≤ i < j < k ≤ n-1, 使得 arr[i] < arr[j] < arr[k] ,返回 true ; 否则返回 false 。
67 0
LeetCode 334. Increasing Triplet Subsequence
|
存储
LeetCode 329. Longest Increasing Path in a Matrix
给定一个整数矩阵,找出最长递增路径的长度。 对于每个单元格,你可以往上,下,左,右四个方向移动。 你不能在对角线方向上移动或移动到边界外(即不允许环绕)。
46 0
LeetCode 329. Longest Increasing Path in a Matrix
【LeetCode】Increasing Triplet Subsequence(334)
  Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
80 0
【1096】Consecutive Factors (20 分)
【1096】Consecutive Factors (20 分) 【1096】Consecutive Factors (20 分)
100 0