随一个序列然后贪心即可。 12345678910111213141516171819202122232425#include<bits/stdc++.h>using namespace std;int n,a[55],v[55][55],cnt[55],b[55];vector<int> ans;mt19937 rd((unsigned long long)new char);int main(){ cin>>n; for(int i=1;i<=n;++i)b[i]=i; int x,y; while(cin>>x>>y)v[x][y]=v[y][x]=1,++cnt[x],++cnt[y]; while(1.0*clock()/CLOCKS_PER_SEC<=0.985){ vector<int> g;g.push_back(b[1]); for(int i=2;i<=n;++i){ if(cnt[b[i]]<g.size())continue; int c=0; for(int j:g)c+=v[b[i]][j]; if(c==g.size())g.push_back(b[i]); } if(ans.size()<g.size())ans=g; if(ans.size()==n)break; shuffle(b+1,b+n+1,rd); } cout<<ans.size()<<'\n'; return 0;}