链接:
1761. 一个图中连通三元组的最小度数
题意:
选择两两相连的三个点,要求度最小
解:
什么暴力hard
实际代码:
#include<bits/stdc++.h>
using namespace std;
int minTrioDegree(int n, vector<vector<int>>& edges)
{vector<int>power(n+1);vector<vector<int>>mp(n+1,vector<int>(n+1));for(auto& edge:edges){mp[edge[0]][edge[1]] = 1;mp[edge[0]][edge[1]] = 1;power[edge[0]]++;power[edge[1]]++;}int ans=INT_MAX;for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){for(int k=j+1;k<=n;k++){if(mp[i][j] && mp[i][k] && mp[j][k]){ans=min(ans,power[i]+power[j]+power[k]-6);}}}}return ans==INT_MAX? -1 : ans;
}
int main()
{int n,m;cin>>n>>m;vector<vector<int>> edges;for(int i=1;i<=m;i++){int a,b;cin>>a>>b;edges.push_back({a,b});}int ans=minTrioDegree(n,edges);cout<<ans<<endl;
}
限制:
2 <= n <= 400
edges[i].length == 2
1 <= edges.length <= n * (n-1) / 2
1 <= ui, vi <= n
ui != vi
- 图中没有重复的边。