强连通子图
1. 原文
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 |
Sample output:
1 | Yes |
2. 解析
连通子图判断:图内边连通 graph[ a ] [ b ] != Inf
强连通子图:子图外的结点不存在与子图内结点都相连的点
set记录子图内结点值,bool visit[]记录访问的子图结点
循环遍历visit为false的结点i,判断该结点是否有与set中的点graph[ i ] [ *j ] != Inf,存在则不是强连通子图
3. AC代码
1 |
|