1142. Maximal Clique

clique代码实现 clique是基于密度与网格的算法。这里用c++实现了clique算法。 立即下载

Maximal Clique

A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from https://en.wikipedia.org/wiki/Clique_(graph_theory))

Now it is your job to judge if a given subset of vertices can form a maximal clique.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers Nv (<= 200), the number of vertices in the graph, and Ne, the number of undirected edges. Then Ne lines follow, each gives a pair of vertices of an edge. The vertices are numbered from 1 to Nv.

After the graph, there is another positive integer M (<= 100). Then M lines of query follow, each first gives a positive number K (<= Nv), then followed by a sequence of K distinct vertices. All the numbers in a line are separated by a space.

Output Specification:

For each of the M queries, print in a line “Yes” if the given subset of vertices can form a maximal clique; or if it is a clique but not a maximal clique, print “Not Maximal”; or if it is not a clique at all, print “Not a Clique”.

Sample Input:

8 10
5 6
7 8
6 4
3 6
4 5
2 3
8 2
2 7
5 3
3 4
6
4 5 4 3 6
3 2 8 7
2 2 3
1 1
3 4 3 6
3 3 2 1

Sample Output:

Yes
Yes
Yes
Yes
Not Maximal
Not a Clique

题意

团为图g中的一个子图h,且该子图中任意两个顶点之间都有一条边,若将图g中任一剩余结点加入到h中都无法使h扩大为更大的一个团,就说h是极大团。

现给定图中所有结点和边,要求判断给定的子图是否是一个团,以及是否是一个极大团。

思路

因为结点数上限仅为200,直接按照定义穷举遍历即可通过。


代码实现

#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

const int maxn = 201;
int nv, ne;
bool g[maxn][maxn] = {false};       // 邻接矩阵
vector<int> cl;                     // 记录子图结点
bool hashTable[maxn] = {false};     // 判断是否为子图结点

bool isClique()     // 判断是否为团
{
    // 直接遍历,判断子图两两结点之间是否有边
    for (int i = 0; i < cl.size() - 1; i++)
        for (int j = i + 1; j < cl.size(); j++)
            if (g[cl[i]][cl[j]] == false)       // 如果无边,说明不是团
                return false;
    return true;
}

bool isMaximal()    // 判断是否为极大团
{
    for (int i = 1; i <= nv; i++)       // 遍历图中所有非子图结点
    {
        if (hashTable[i] == false)
        {
            bool flag = true; 
            for (int j = 0; j < cl.size(); j++)     // 判断该结点是否与所有子图结点有边
                if (g[i][cl[j]] == false)           // 若无边,说明添加该结点无法扩大团
                    flag = false;
            if (flag == true)       // 若与所有子图结点都有边,说明不是极大团
                return false;
        }
    }
    return true;
}

int main()
{
    int a, b;
    int m, k, x;

	scanf("%d%d", &nv, &ne);
    for (int i = 0; i < ne; i++)
    {
        scanf("%d%d", &a, &b);
        g[a][b] = g[b][a] = true;
    }

    for (int i = 1; i <= nv; i++)       // 注意结点与自身之间要定义为有边
        g[i][i] = true;

    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        // 初始化操作
        memset(hashTable, false, sizeof(hashTable));
        cl.clear();

        scanf("%d", &k);
        for (int j = 0; j < k; j++)
        {
            scanf("%d", &x);
            cl.push_back(x);
            hashTable[x] = true;        // 标记子图结点
        }

        if (isClique() == false)
            printf("Not a Clique\n");
        else if (isMaximal() == false)
            printf("Not Maximal\n");
        else
            printf("Yes\n");
    }

    return 0;
}
SECS/GEM协议库及开源代码 以下是在开发SECS/GEM协议过程中,在网络上搜集协议实现资源,希望对SECS/GEM协议感兴趣的同学能有所帮助。 开源代码 freesecs FREESECS 是一个开源的SEMI SECS协议库,采用C++语言实现,可运行于Linux, MacOS X, NetBSD。 实现协议:E37.1、E5 开源地址:freesecs download | SourceForge.net 下载地址:https://download.csdn.net/download/BT_LEO/24305429 阅读详情

相关推荐

登临科技Goldwasser加速卡Python SDK实战:从环境配置到YOLOv5模型性能压测

本文详细介绍了登临科技Goldwasser加速卡的Python SDK实战指南,从环境配置到YOLOv5模型性能压测的全过程。通过驱动安装、SDK环境搭建、模型转换与推理优化等步骤,帮助开发者高效利用AI加速卡提升深度学习模型性能。重点分享了批量推理压测技巧和常见问题解决方案,助力开发者充分发挥Goldwasser加速卡的算力优势。

weixin_29035147的博客 300

1142 Maximal Clique

1142 Maximal Clique 题目大意 clique是一个点集,在一个无向图中,这个点集中任意两个不同的点之间都是相连的。maximal clique是一个clique,这个clique不可以再加入任何一个新的结点构成新的clique。点编号从1~n,给出m条边,以一对结点编号的方式给出。然后给出m条询问,每个询问是一个点集合,问这个点集合是否是maximal clique、是否是clique。 基本思路 在每一组测试样例中,定义一个数组v存放所有测试样例中的元素,数组hashtable表示该顶点

Baifeili的博客 657

【Solidworks学习使用(1)__2022版本保姆级安装方法】

Solidworks 2020安装

coder-kimbell的博客 6253

PAT A1142 Maximal Clique (25 分)

PAT A1142 Maximal Clique (25 分)

zhengqinyuanbift的博客 320

OpenRA引擎实战:如何从零开始搭建一个经典RTS游戏模组(附资源包)

本文详细介绍了如何利用开源游戏引擎OpenRA从零开始搭建经典RTS游戏模组。内容涵盖开发环境配置、资源管线处理、YAML规则定义、地图编辑与Lua脚本编写等全流程实战指南,并提供了资源包,帮助开发者和爱好者快速创建属于自己的即时战略游戏世界。

silver的专栏 903

告别二极管发热!手把手教你用MOS管搭建同步整流电路(附死区时间设置避坑指南)

本文详细介绍了如何利用MOS管搭建同步整流电路(SR),以替代传统二极管,显著降低导通损耗和发热问题。内容涵盖自驱动方案的选择、关键元件参数计算、PCB布局要点及死区时间设置技巧,帮助工程师优化电源设计效率。

weixin_29540599的博客 451

最大团算法(Maximum Clique)

1.问题描述 最大团问题是图论中一个经典的组合优化问题,也是一类NP完全问题。在Wikipedia中Clique Problem的描述如下: In computer science, the clique problem refers to any of the problems related to finding particular complete subgraphs ("clique

GatsbyNewton 1万+

Unity抖音小游戏上架实战:从零到一,详解流程与避坑指南

本文详细介绍了Unity抖音小游戏上架的全流程,包括环境准备、SDK集成、开发者账号注册、软著申请、打包提交流程及常见问题解决方案。重点解析了抖音小游戏平台特有的配置细节和避坑技巧,帮助开发者高效完成游戏上架并优化用户体验。

weixin_33704234的博客 261

团、极大团、最大团

Bron-Kerbosch算法视频介绍极大团介绍团、极大团介绍 团(clique) 引自wiki: a clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. 意思就是团(clique)就是一个无向图的完全子图,既然是完全图,当然每对顶点之间都必须要有边相连。 团:无向图的完全子图。 完全图:完全图是一个简单的无向..

wangprince2017 2888

AD22等长布线规则

本文介绍了PCB布线中实现信号线等长的详细操作步骤:1.创建网络类(NetClass),将需要等长的信号线归入同一组;2.设置高速布线规则(High-SpeedRule),定义等长容差等参数;3.进行交互式等长布线(InteractiveLengthTuning),使用蛇形线调整线长;4.实时调整与最终检查,确保所有网络满足等长要求。文中还提供了实用技巧,如使用快捷键调整蛇形线参数、为关键信号设置更严格规则等。操作需在PCB设计软件中完成,通过统一管理、规则设置和精确调整来实现信号同步传输。

whm128的博客 1557

PyTorch强化学习实战(3)——Gymnasium API扩展功能

我们已经学习了编写智能体必需的 Gymnasium 核心功能,其余 API 功能部分虽然非必需,但能显著提升开发效率和代码整洁度。在本节中,我们简要地介绍了 Gymnasium API 的扩展功能,学习了如何以模块化的方式扩展现有环境的功能,并熟悉了使用包装器可视化智能体活动的方法。

盼小辉丶的博客 1195

PAT A1142 Maximal Clique 题解

clique(团)是一个点集,在一个无向图中,这个点集中任意两个不同的点之间都是相连的。maximal clique是一个clique,这个clique不可以再加入任何一个新的结点构成新的clique。然后给出m条询问,每个询问是一个点集合,问这个点集合是否是maximal clique、是否是clique。之后判断是否是maximal,即遍历所有不在集合中的剩余的点,看是否存在一个点满足和集合中所有的结点相连,最后如果都满足,那就输出Yes表示是Maximal clique。

qq_45554473的博客 286

激光雷达与相机时间戳同步:原理、触发方案与工程实现

目录一、引言:时间不同步,多传感器融合必出问题二、核心原理:相机成像机制与触发模式(同步的基础)2.1 相机成像的两个核心阶段:曝光与读出(1)非交叠曝光(2)交叠曝光2.2 相机触发模式:内触发 vs 外触发(1)内触发(2)外触发2.3 关键信号:Strobe信号与预输出(同步的核心技巧)三、三种主流时间戳同步方案(工程落地首选)3.1 方案一:统一硬触发(精度最高,高端场景首选)核心原理核心配置要点优缺点适用场景3.2 方案二:软触发+硬触发(Strobe预输出,车载量产首选)核心原理核心配置要点优缺

getusushu的博客 200

【PAT甲级】1142 Maximal Clique

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 430

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

1142 Maximal Clique (25 分)*

跟着柳婼学姐学习的笔记ヾ(≧▽≦*)o题意分析CODE 原题目: 1142 Maximal Clique (25 分). 题意 clique是一个点集,在一个无向图中,这个点集中的任意两个不同点之间都是相连的。maximal clique是一个clique,这个clique再加入一个新的结点就不是clique了。 分别给出顶点和无向边数Nv和Ne,以及每条边所连两个顶点的序号(1-Nv), ????判断所给顶点是否构成maximal clique或者clique。 分析 先判断是否是clique——判断任

Mic_Mickey的博客 318

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PAT 1142 Maximal Clique[难]

1142Maximal Clique(25 分) Acliqueis a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Amaximal cliqueis a clique that cannot be ...

weixin_33834679的博客 111

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

PAT 1142 Maximal Clique

PAT 1142 Maximal Clique

2301_80219163的博客 209

PAT 甲级 1142  Maximal Clique

1142Maximal Clique(25 point(s)) Acliqueis a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Amaximal cliqueis a clique that cannot be...

漫浸天空的雨色的备忘录~ 859

PAT-ADVANCED1142——Maximal Clique

我的PAT-ADVANCED代码仓:https://github.com/617076674/PAT-ADVANCED 原题链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 题目描述: 题目翻译: 1142 最大Clique clique是无向图的顶点的子集,使得cliqu...

清风阁 358

1142 Maximal Clique (25分)

A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex. (Quoted from https://en.wikipedia.org/wiki

白小飞 210
上一篇: 1010. Radix
下一篇: 1143. Lowest Common Ancestor
绿色小光头
博客等级 码龄10年 10粉丝 301原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值