To ensure victory in the elections, the mayor decided to build a team of his friends, where everyone is a friend of each other. Knowing the relationship between an all N acquaintances mayor to build a team the greatest number of M. When the existence of multiple solutions is sufficient to derive only one of them.
Input
The first line is a single number N - the number of acquaintances Mayor (N < 50). In the second row - the number of K - the number of couples who have friendly relations. The following K lines through space-separated pair of numbers - numbers of friends.
Output
The first line of a single number - the largest squad of the mayor. The next line through the gap of the mayor's team in ascending numerical order.
Input
The first line is a single number N - the number of acquaintances Mayor (N < 50). In the second row - the number of K - the number of couples who have friendly relations. The following K lines through space-separated pair of numbers - numbers of friends.
Output
The first line of a single number - the largest squad of the mayor. The next line through the gap of the mayor's team in ascending numerical order.
5 6 1 2 2 3 1 3 4 5 1 5 3 4
#include <iostream> using namespace std; //记录最优解,s[0]记录最优解个数 int best_s[60] = {0}; int now_s[60] = {0}; int G[60][60] = {0}; bool judge(int index){ for(int i = 1; i <= now_s[0]; i++){ if(G[now_s[i]][index] == 0) return false; } return true; } void DFS(int index,int MAX){ if(index > MAX) { //更新最优解 if(now_s[0] > best_s[0]){ for(int i = 1; i <= now_s[0]; i++){ best_s[i] = now_s[i]; } best_s[0] = now_s[0]; } return; } // 判断加入index是否还是完全图 // 是则加入或者丢弃 if(judge(index)){ //加入 now_s[0]++; now_s[now_s[0]] = index; DFS(index+1, MAX); //丢弃 now_s[now_s[0]] = 0; now_s[0]--; DFS(index+1, MAX); } // 不是直接丢弃 else{ DFS(index+1, MAX); } } int main(){ int N, K; cin>>N>>K; for(int i = 0; i < K; i++){ int a, b; cin>>a>>b; G[a][b] = 1; G[b][a] = 1; } DFS(1,N); cout<<best_s[0]<<endl; for(int i = 1; i <= best_s[0]; i++){ if(i != 1) cout<<" "; cout<<best_s[i]; } return 0; }//;来自寄意寒星