算一下复杂度。发现可以直接暴。对于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. springboot2 -广播式WebSocket

    1.WebSocket,STOMP,SockJS含义 WebSocket:WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议. SockJS:SockJS 是 We ...

  2. http协议之基础概念篇(1)

    内容概述: 该篇主要内容概述 a.http相关术语解析 b.http的基本原理与工作流程 c.相关工具的使用(Wireshark) 作用介绍 绝大多数的web开发,都是构建在http协议之上的. HT ...

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

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

  4. CodeForces 689C【二分】

    转自: http://blog.csdn.net/qq_26071477/article/details/51892995 #include<stdio.h> typedef long l ...

  5. [Xcode 实际操作]七、文件与数据-(21)ARKit增强现实框架的使用

    目录:[Swift]Xcode实际操作 本文将演示ARKit增强现实框架的使用. 创建一个新的项目:[Create a new Xcode project] ->在打开的模板选择中,选择增强现实 ...

  6. extern用法详解(转)

    1 基本解释 extern可以置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义. 另外,extern也可用来进行链接指定. 2 问题:ext ...

  7. react-native-wechat微信组件的使用

    对我来说link没有成功过,所以参考了其他人的文章,原文:https://www.jianshu.com/p/6a792118fae4 第一步:要去:https://open.weixin.qq.co ...

  8. java数据结构----队列,优先级队列

    1.队列:和栈中的情况不同,队列中的数据项不总是从数组下标0开始,移除一个数据项后,队头指针会指向下标较高的数据项,其特点:先入先出 2.图解 3.队列的实现代码: 3.1.Queue.java pa ...

  9. ( 2018 Multi-University Training Contest 2)

    2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...

  10. 116 Populating Next Right Pointers in Each Node 每个节点的右向指针

    给定一个二叉树    struct TreeLinkNode {      TreeLinkNode *left;      TreeLinkNode *right;      TreeLinkNod ...