题解:P15972 「RedStone OI R10 A」菊花残
zzrzzr114514 · · 题解
解题思路
题目要求我们求出最大的菊花子图。我们可以枚举中间点,然后取出所有邻居节点,这就是以这个点为中心的最大的菊花子图。注意本题数据有可能重边和自环,需要去重。
AC 代码
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
vector<set<int>> gra(n+1);
while(m--)
{
int u,v;
cin>>u>>v;
if(u==v) continue;
gra[u].emplace(v);
gra[v].emplace(u);
}
int res=1;
for(int i=1;i<=n;++i)
{
res=max(res,(int)gra[i].size()+1);
}
cout<<res;
}