算一下复杂度。发现可以直接暴。对于u枚举a和b,判断一下是否连边,更新答案。

#include<bits/stdc++.h>
using namespace std; int n,m;
const int maxn = ;
#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 = ; 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 = ; u <= n; u++){
int sz = G[u].size();
for(int i = ; i < sz; i++){
int a = G[u][i];
for(int j = i+; j < sz; j++){
int b = G[u][j];
if(g[a][b]){
ans = min(ans,deg[u]+deg[a]+deg[b]-);
}
}
}
}
if(ans<INF){
printf("%d\n",ans);
}else printf("-1\n");
return ;
}

Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)的更多相关文章

  1. Codeforces Round #318 (Div. 2) D Bear and Blocks (数学)

    不难发现在一次操作以后,hi=min(hi-1,hi-1,hi+1),迭代这个式子得到k次操作以后hi=min(hi-j-(k-j),hi-k,hi+j-(k-j)),j = 1,2,3... 当k ...

  2. Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)

    优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...

  3. Codeforces Round #318 (Div. 2) C Bear and Poker (数学)

    简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...

  4. Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  5. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)

    A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力

    D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...

  8. Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块

    E. Bear and Square Grid 题目连接: http://www.codeforces.com/contest/680/problem/E Description You have a ...

  9. Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs

    D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...

随机推荐

  1. C++11: Multi-core Programming – PPL Parallel Aggregation Explained

    https://katyscode.wordpress.com/2013/08/17/c11-multi-core-programming-ppl-parallel-aggregation-expla ...

  2. Channel的使用

    Channel必须要通过buffer来读写 1. Channel需要通过IO流的getChannel()方法获取 2. buffer需要通过Channel的map()方法获取 package com. ...

  3. Lightoj 1147【DP】

    题意: 把n个人分成两部分,要你怎么分使得两部分尽可能相等: 思路: 如果我们把一部分人的重量达到离sum/2最近,那就一定行啊 其实就是一条棒,两种不同的棒去拼接成一条棒,然后最好就是离mid最近, ...

  4. Lightoj1081【500棵线段树维护】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=5e2+10; const ...

  5. 微信API接口文档

    传送门

  6. 慕课笔记-Java入门第一季

    [初步复习Java编程基础,记录知识盲点和遗漏点] 1.switch语法 switch(表达式){ case 值1: 执行代码块1; break; case 值2: 执行代码块12; break; c ...

  7. eclipse添加tomcat运行环境

  8. Java相关书籍阅读

  9. Python-2-序列及通用序列操作

    序列包括字符串,列表,元祖,序列中的每个元素都有编号,其中只有元祖不能修改   通用序列操作包括索引. 切片. 相加. 相乘和成员资格检查   索引 >>> greeting = ' ...

  10. python模块之struct

    # #********struct模块********# # 1.按照指定格式将Python数据转换为字符串,该字符串为字节流,如网络传输时, # 不能传输int,此时先将int转化为字节流,然后再发 ...