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 ...
随机推荐
- http://www.cnblogs.com/yaozhenfa/archive/2015/06/14/4574898.html
笔者这里采用的是mongoDB官网推荐使用.net驱动: http://mongodb.github.io/mongo-csharp-driver/2.0/getting_started/quick_ ...
- GitHub的使用方法
版本控制系统 > Git 分布式 > Subversion 集中式 1. 安装git: # apt-get install git //root权限 $ sudo apt-get inst ...
- ++i和i++的效率孰优孰劣
在内建数据类型的情况下,效率没有区别: 在自定义数据类型的情况下,++i效率更高! 分析: (自定义数据类型的情况下) ++i返回对象的引用: i++总是要创建一个临时对象,在退出函数时还要销毁它,而 ...
- eclipse编辑窗口不见了(打开左边的java、xml文件,中间不会显示代码)
转自:https://blog.csdn.net/u012062810/article/details/46729779?utm_source=blogxgwz4 1. windows-->re ...
- 【216】◀▶ IDL 字符串操作说明
参考:String Processing Routines —— 字符串处理函数 01 STRING 返回字符串. 02 STRCMP 比较字符串,一样返回1,不一样返回0,默认大小写敏感. ...
- 改变bootstrapSwitch按钮状态
$('.switch-state').bootstrapSwitch('state',true);
- vsftpd总结
1 vsftps配置文件详解 (1)/user/sbin/vsftpd 主程序 (2)/etc/rc.d/init.d/vsftpd 启动脚本 (3)/etc/pam.d/vsftpd (file= ...
- 极客时间_Vue开发实战_07.Vue组件的核心概念(3):插槽
07.Vue组件的核心概念(3):插槽 严格来的说在2.0之后已经不分区这两种插槽的概念了. 因为它底层的实现已经趋向于相同了. 2.6为了兼容2.5的版本,现在依然可以用这两种写法 作用域插槽就是多 ...
- linux常用命令的全拼
Linux常用命令英文全称与中文解释Linux系统 Linux常用命令英文全称与中文解释linux系统 man: Manual 意思是手册,可以用这个命令查询其他命令的用法. pwd:Print ...
- Eclipse SVN 图标解释
[转]http://blog.sina.com.cn/s/blog_64941c8101018dno.html - 已忽略版本控制的文件.可以通过Window → Preferences → Team ...