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. wpf图片定点缩放

    去年犯小人,万事不顺,4月刚换工作,开始新工作 遇到一个小问题,需要读取图片,然后对图片进行定点缩放,很简答的逻辑,很简单的代码,但是,这尼玛我被wpf给坑了,这一坑就是三天 好了,很简单的一个UI ...

  2. gzhu 2013 Good Sequence 解题报告

    题目链接:(这个是内网的网址)  http://172.22.27.1/problem?pid=1013 Good Sequence Time Limit: 4000/2000 MS (Java/Ot ...

  3. JS倒计时,距离某一日期还有多少时间

    JS计算从现在到某个时刻还有多少时间,显示当前日期时间距离x年x月x日还有x天x小时x分钟x秒,如果给定时间比当前时间更早,则显示为距离2012-9-30已过去1天22小时26分30秒的格式,如果给定 ...

  4. mycat的事务支持情况

    中秋国庆一共12天,玩的有点嗨,完全没想工作的事情- -.回来赶紧补补.看了一下mycat关于事务的支持情况,做一下记录. 说mycat的事务支持之前,先说说XA协议,即分布式事务.指的是TM(事务管 ...

  5. hdu-5744 Keep On Movin(思维)

    题目链接: Keep On Movin Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Oth ...

  6. UVA-11374(最短路)

    题意: 机场快线有经济线和商业线,现在分别给出经济线和商业线的的路线,现在只能坐一站商业线,其他坐经济线,问从起点到终点的最短用时是多少,还有路线是怎样的; 思路: 预处理出起点到所有站的最短距离和终 ...

  7. POJ3061 Subsequence

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16520   Accepted: 7008 Desc ...

  8. 11.boolean类型

    /* 关于java中的Boolean类型: 1)赋给boolean类型的值只有两个:ture或者false 2)boolean类型的数据主要用在逻辑运算和条件控制语句中.*/ public class ...

  9. aidl笔记 2/5/2015

    interface Test { //测试的接口 void fun();} Stub 是一个Binderclass Stub extend Binder implements Test { publi ...

  10. c语言里如何调用汇编里的变量?

    c语言里如何调用汇编里的变量? 汇编语言:是声明全局变量 .globl _end_ofs _end_ofs: .word _end - _start c语言:声明这个变量,然后再调用这个变量 void ...