Gym 101149I I - It's the Police
http://codeforces.com/gym/101149/problem/I
考虑下面这个例子
4 3
1 2
1 3
1 4
应该是选 0 0 1 1这样是最优的,我们不选1号,因为如果选1号作为非法分子点,那么2、3、4也不能有警察了,这不行。
那么究竟选呢?
很明显的一个道理是,选出儿子数最小的那个点,作为非法分子点,那么不放警察的地方就变得小了。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = 2e5 + ;
vector<int>son[maxn];
bool vis[maxn];
void work() {
IOS;
int n, m;
cin >> n >> m;
for (int i = ; i <= m; ++i) {
int u, v;
cin >> u >> v;
son[u].push_back(v);
son[v].push_back(u);
}
int mi = inf;
int id = inf;
for (int i = ; i <= n; ++i) {
if (son[i].size() < mi) {
mi = son[i].size();
id = i;
}
}
vis[id] = ;
for (int i = ; i < son[id].size(); ++i) {
vis[son[id][i]] = ;
}
for (int i = ; i <= n; ++i) {
printf("%d ", !vis[i]);
}
}
int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
Gym 101149I I - It's the Police的更多相关文章
- Gym - 101908H Police Hypothesis (树链剖分/LCT+字符串哈希)
题意:有一棵树,树上每个结点上有一个字母,有两种操作: 1)询问树上两点u,v间有向路径上有多少个字母和某个固定的字符串相匹配 2)将结点u的字母修改为x 树剖+线段,暴力维护前缀和后缀哈希值(正反都 ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
随机推荐
- 渗透模型 Percolation Models(一个物理模型的广泛应用)
转自:http://mooc.guokr.com/note/15357/ http://mooc.guokr.com/user/0298406005/note/ 模型思想: 有水流下来,是否会渗入地面 ...
- ffmpeg 中av_rescale_rnd 的含义
http://blog.csdn.net/fireroll/article/details/8485482 一.函数声明: int64_t av_rescale_rnd(int64_t a, int6 ...
- Sublime Text 相关教程(转)
曾经有人说过,世界上有两种编辑器,好用和不好用的:而在好用的编辑器中,又分两种,免费的和死贵死贵的.譬如说VIM 和 TextMate,就是免费和死贵的典型.很不幸,今天的主角 Sublime Tex ...
- PHP 中$_SERVER的用法
php编程中经常需要用到一些服务器的一些资料,我把常用的用高亮的方式贴出来,其余的放在后面.方便以后查阅$_SERVER['HTTP_ACCEPT_LANGUAGE']//浏览器语言 $_SERVER ...
- 机器学习 : 高斯混合模型及EM算法
Mixtures of Gaussian 这一讲,我们讨论利用EM (Expectation-Maximization)做概率密度的估计.假设我们有一组训练样本x(1),x(2),...x(m),因为 ...
- 多线程之:volatile变量的一次写操作的过程
一:对volatile修饰的变量进行一次写操作的完整过程 在 java 垃圾回收整理一文中,描述了jvm运行时刻内存的分配.其中有一个内存区域是jvm虚拟机栈,每一个线程运行时都有一个线程栈,线程 ...
- WinDbg 调试工具的使用
概述 项目接近尾声了,可是在运行时会有memory leak(内存泄露) bug.产品在运行一天后,内存增长致1.4G,而我们产品的初始内存才有70M,问题很严重,决定采用WinDbg工具来分析代码问 ...
- YoutubeAPI使用
YoutubeAPI使用 1 Youtube API能干什么 2 Youtube API 2.0 Youtube简介 2.1 如何使用Youtube API 2.1.1 获取Youtube 的开发 ...
- PBE加密算法
这是我参加全国信息安全大赛的设计的加密系统中的一个加密算法,虽然比赛的结果不是非常理想但是,我还是学到了很多东西,现在和大家分享一下,比赛收获的东西. 基于口令加密 PBE(Password Base ...
- 蓝桥杯 2014本科C++ B组 李白打酒 三种实现方法 枚举/递归
标题:李白打酒 话说大诗人李白,一生好饮.幸好他从不开车. 一天,他提着酒壶,从家里出来,酒壶中有酒2斗.他边走边唱: 无事街上走,提壶去打酒. 逢店加一倍,遇花喝一斗. 这一路上,他一共遇到店5次, ...