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的更多相关文章

  1. Gym - 101908H Police Hypothesis (树链剖分/LCT+字符串哈希)

    题意:有一棵树,树上每个结点上有一个字母,有两种操作: 1)询问树上两点u,v间有向路径上有多少个字母和某个固定的字符串相匹配 2)将结点u的字母修改为x 树剖+线段,暴力维护前缀和后缀哈希值(正反都 ...

  2. 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 ...

  3. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  4. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  5. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  6. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  7. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  8. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  9. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

随机推荐

  1. starUML安装与破解

    安装包百度云: 链接:https://pan.baidu.com/s/1oF_DH7Xh6yun6fFUDB2H3w 密码:1z7e 破解步骤:1. 首先打开你的starUML安装目录,并找到Lice ...

  2. poj2728 Desert King——01分数规划

    题目:http://poj.org/problem?id=2728 第一道01分数规划题!(其实也蛮简单的) 这题也可以用迭代做(但是不会),这里用了二分: 由于比较裸,不作过多说明了. 代码如下: ...

  3. java 整除(/) 求余(%) 运算

    1. java 整除(/)  求余(%)  运算 1.求余    System.out.println(11%2);     //顾名思义就是11除2的余数-->1    System.out. ...

  4. shell脚本自动部署nignx反向代理及web服务器,共享存储

    #!/bin/bash systemctl status nginx var=$? ] then yum install epel-release -y ] then echo "epel库 ...

  5. 创建Python本地副本

    创建本地副本后可以避免解释器找不到模块的情况. 1. 创建一个测试用的pl.py def printTest(): print("this is a test") 2. 将pl.p ...

  6. AtCoder Grand Contest 005【A栈模拟,B单调栈】

    挖草,AtCoder实在是太吊了~ %%%,目前只A了两题: A题: 就是利用栈模拟一下就好了:S进栈,T的话有S就出栈,然后len减一下就好了: #include <bits/stdc++.h ...

  7. hdoj5493【树状数组+二分】

    题意: 给你n个人的高度, 再给出一个值代表该高度下有前面比他高的 或 后面比他高的人数, 求满足条件下的最小字典序, 不行的话输出"impossible" 思路: 对于最小字典序 ...

  8. UVA12504【C++STL运用】

    雨巨的UVA的C++题集英文真长- 题意: 有两本字典,第一行是旧字典,第二行是新字典. 每行不超过100个字符,没有空格,两本字典都可以是空的: 新key:+ 缺key:- 值变 :* 思路: 具体 ...

  9. Tessellation

    Tessellation细分曲面技术是AMD(ATI)常年研发多代的技术,经过多年发展最终被采纳成为DX11的一项关键技术,因此历来都是宣传重点.和光线追踪不同,现在的光栅化图形渲染技术的核心是绘制大 ...

  10. Scut

    这是一款免费开源的游戏服务器引擎,适用于开发AVG.SLGRPG.MMOG等类型的网络游戏,同时支持Http.WebSocket和Socket协议通讯,支持Window.Mac和Linux多种平台部署 ...