Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
算一下復雜度。發現可以直接暴。對于u枚舉a和b,判斷一下是否連邊,更新答案。
#include<bits/stdc++.h> using namespace std;int n,m; const int maxn = 4001; #define PB push_back vector<int> G[maxn]; bool g[maxn][maxn]; int deg[maxn]; const int INF = 0x3f3f3f3f; int main() {//freopen("in.txt","r",stdin);scanf("%d%d",&n,&m);for(int i = 0; i < m; i++){int a,b;scanf("%d%d",&a,&b);deg[a]++; deg[b]++;g[a][b] = g[b][a] = true;G[a].PB(b); G[b].PB(a);}int ans = INF;for(int u = 1; u <= n; u++){int sz = G[u].size();for(int i = 0; i < sz; i++){int a = G[u][i];for(int j = i+1; j < sz; j++){int b = G[u][j];if(g[a][b]){ans = min(ans,deg[u]+deg[a]+deg[b]-6);}}}}if(ans<INF){printf("%d\n",ans);}else printf("-1\n");return 0; }?
轉載于:https://www.cnblogs.com/jerryRey/p/4770261.html
總結
以上是生活随笔為你收集整理的Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么要抵制四字和吴京?
- 下一篇: form表单,submit,ajax提交