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 = ;
#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 (暴力)的更多相关文章
- 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 ...
- Codeforces Round #318 (Div. 2) A Bear and Elections (优先队列模拟,水题)
优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main( ...
- Codeforces Round #318 (Div. 2) C Bear and Poker (数学)
简单题,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. 求lcm,爆了long long.我得好好反省一下,对连乘不敏感 #include<bits/stdc++.h&g ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 【网络爬虫】【python】网络爬虫(四):scrapy爬虫框架(架构、win/linux安装、文件结构)
scrapy框架的学习,目前个人觉得比较详尽的资料主要有两个: 1.官方教程文档.scrapy的github wiki: 2.一个很好的scrapy中文文档:http://scrapy-chs.rea ...
- Laravel之简单的学生信息管理平台
laravel框架写的简易版的学生信息管理平台,贯穿了laravel的控制器.视图.模板.模型.中间件.路由规则的使用. 页面是使用BootStrap前端框架搭建 使用laravel实现了增删改查的功 ...
- UVa 242 Stamps and Envelope Size (无限背包,DP)
题意:信封上最多贴S张邮票.有N个邮票集合,每个集合有不同的面值.问哪个集合的最大连续邮资最 大,输出最大连续邮资和集合元素. 最大连续邮资是用S张以内邮票面值凑1,2,3...到n+1凑不出来了,最 ...
- Installing cmake 2.8.8 or higher on Ubuntu 12.04 (Precise Pangolin) (转载)
转自:http://cameo54321.blogspot.com/2014/02/installing-cmake-288-or-higher-on.html Check the version o ...
- PhpStorm插件之Api Debugger
安装插件 File->Setting->Pluugins 搜索 Api Debugger 如何使用 安装完插件后,RESTART IDE,在编辑器右侧 即可找到最新安装的 Api D ...
- Lightoj 1021【状压DP(未搞)】
状态压缩一下,然后DP还是很容易想到,dp[i][j]表示状态为i时,模 k 为 j 的排列数的个数,然后每次对一个状态扩展,添加新的数字: 然而那个取膜没懂.....
- Memcached 查看帮助
进入到memcached目录, 输入命令: memcached -h 即可查看帮助 -p<num>要侦听的TCP端口号(默认值:11211) -u<num>udp监听端口号(默 ...
- jzoj5991. 【北大2019冬令营模拟2019.1.6】Juice
题面 题解 好迷-- //minamoto #include<bits/stdc++.h> #define R register #define ll long long #define ...
- P5136 sequence(矩阵快速幂)
传送门 数列的特征方程和特征根老师上课好像讲过然而我没听--以后老师上数学课要认真听了QAQ 设\(x=\frac{1+\sqrt{5}}{2},y=\frac{1-\sqrt{5}}{2}\),那么 ...
- VRTK3.3.0-004传送
直线传送: 一.无高度变换传送(VRTK_BasicTeleport) 1丶继续在VRScripts下创建空物体PlayArea,用来挂在传送相关脚本:创建Plane作为传送地面 2丶在PlayAre ...