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 ...
随机推荐
- Unity3D中调用外接摄像头,并保存为图片文件
http://bbs.9ria.com/thread-170539-1-1.html 项目要求调用摄像头,并且把图像保存下来,上传到服务器. 这里有几个难点,调用摄像头是很简单的,unity已经提供好 ...
- [Xcode 实际操作]八、网络与多线程-(15)使用网址会话对象URLSession下载图片并存储在沙箱目录中
目录:[Swift]Xcode实际操作 本文将演示如何通过网址会话对象URLSession下载图片并存储在沙箱目录中. 网址会话对象URLSession具有在后台上传和下载.暂停和恢复网络操作.丰富的 ...
- 你了解SVN, CVS等版本控制器吗?
版本控制器SVN, CVS是两种版本控制器, 需要配套相关的SVN, CVS服务器, SCM是xcode里面配置版本控制的地方, 版本控制的原理就是A和B同时开发一个项目, A写完当天的代码之后把代码 ...
- html table导出到Excel中,走后台保存文件,js并调用另保存
tableToExcel工具类,此工具类指定格式的表格进行转Excel 格式:其中不能带有thead,tbody和th标签 <table> <tr> <td>表头1 ...
- springboot2.x 的 RedisCacheManager变化
springboot2.x 的 RedisCacheManager变化 springboot2.x 的 RedisCacheManager变化 由于最近在学着使用redis做缓存,使用的是spring ...
- js截取文件名不带后缀
利用正则表达式是匹配后缀名 一般文件后缀都为.xxx,也就是说从尾部匹配的话首先是字母,接着应该有一个. 那么我们就开始写正则表达式 利用在线工具 方便我们编写边测试 一般都是小写字母,所以我们用[a ...
- jsp内置对象分析
1.html表单的提交方式比较: 1.1.get方式:将表单内容经过编码之后 ,通过URL发送, 使用get方式发送时有255个字符的限制. 1.2.post方式:将表单的内容通过http发送,pos ...
- with rollup
实验吧的一道ctf题,这两天无聊,做做ctf题.在实验吧被一道也题卡了好久. 页面很简单就是一个登陆页面,按照之前的经验觉得应该是注入吧.再看题猜测应该是绕waf之类的. 查看页面源码找到了提供的源代 ...
- Jasper_crosstab_Parameter_Crosstab Header
corsstab: Q : how to show filed value at crosstab Header Part? A : via pass parameter in crosstab. i ...
- IE_Script70:没有权限问题处理
IE9浏览器执行JS时报"SCRIPT70:没有权限"错误. 经百度,发现原来与jQuery版本有关系,在jQuery1.9.1版本时会有此问题,升级版本即可.