码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1142 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:

    1. 8 10
    2. 5 6
    3. 7 8
    4. 6 4
    5. 3 6
    6. 4 5
    7. 2 3
    8. 8 2
    9. 2 7
    10. 5 3
    11. 3 4
    12. 6
    13. 4 5 4 3 6
    14. 3 2 8 7
    15. 2 2 3
    16. 1 1
    17. 3 4 3 6
    18. 3 3 2 1

    Sample Output:

    1. Yes
    2. Yes
    3. Yes
    4. Yes
    5. Not Maximal
    6. Not a Clique
    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. int ne, nv, m, k, u, v;
    6. int a[300];
    7. bool g[300][300];
    8. bool vis[300];
    9. int main() {
    10. cin >> nv >> ne;
    11. for (int i = 1; i <= nv; i++) {
    12. g[i][i] = 1;
    13. }
    14. for (int i = 0; i < ne; i++) {
    15. cin >> u >> v;
    16. g[u][v] = g[v][u] = 1;
    17. }
    18. cin >> m;
    19. while (m--) {
    20. cin >> k;
    21. int flag = 0;
    22. memset(vis, 0, sizeof(vis));
    23. for (int i = 0; i < k; i++) {
    24. cin >> a[i];
    25. vis[a[i]] = 1;
    26. }
    27. for (int i = 0; i < k; i++) {
    28. if (flag == 1) {
    29. break;
    30. }
    31. for (int j = i + 1; j < k; j++) {
    32. if (!g[a[i]][a[j]]) {
    33. flag = 1;
    34. break;
    35. }
    36. }
    37. }
    38. if (flag == 1) {
    39. cout << "Not a Clique" << endl;
    40. continue;
    41. }
    42. if (flag == 0) {
    43. for (int i = 1; i <= nv; i++) {
    44. if (flag == 2) {
    45. break;
    46. }
    47. if (!vis[i]) {
    48. vis[i] = 1;
    49. int j = 0;
    50. while (j < k && g[i][a[j]]) {
    51. j++;
    52. }
    53. if (j == k) {
    54. flag = 2;
    55. break;
    56. }
    57. }
    58. }
    59. }
    60. if (flag == 2) {
    61. cout << "Not Maximal" << endl;
    62. } else {
    63. cout << "Yes" << endl;
    64. }
    65. }
    66. return 0;
    67. }
  • 相关阅读:
    对vuex的理解,必须知道的知识点
    【代码随想录】算法训练计划21、22
    【AI-GitHub】SceneScript 3D场景主体识别分割!让AR和人工智能设备了解物理空间的几何形状!
    231.2的幂
    Java项目使用自定义的公共单元(Maven管理)
    基于QT技术实现无线点菜系统设计与实现
    杰理之解码请求参数解析【篇】
    【正点原子FPGA连载】 第三章 硬件资源详解 摘自【正点原子】DFZU2EG/4EV MPSoC 之FPGA开发指南V1.0
    linux进阶(脚本编程/软件安装/进程进阶/系统相关)
    Linux Centos内网环境中安装mysql5.7详细安装过程
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/128068793
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号