洛谷 P3496 [POI2010]GIL-Guilds
题目描述
King Byteasar faces a serious matter.
Two competing trade organisations, The Tailors Guild and The Sewers Guild asked, at the same time, for permissions to open their offices in each town of the kingdom.
There are towns in Byteotia.
Some of them are connected with bidirectional roads.
Each of the guilds postulate that every town should:
have an office of the guild, or be directly connected to another town that does.
The king, however, suspects foul play. He fears that if there is just a single town holding the offices of both guilds, it could lead to a clothing cartel.
For this reason he asks your help.
给一张无向图,要求你用黑白给点染色,且满足对于任意一个黑点,至少有一个白点和他相邻;对于任意一个白点,至少有一个黑点与他相邻,问能否成功
输入输出格式
输入格式:
Two integers, and
(
,
), are given in the first line of the standard input. These denote the number of towns and roads in Byteotia, respectively.
The towns are numbered from to
.
Then the roads are given as follows: the input line no. describes the
-th road; it holds the numbers
and
(
,
), denoting that the  - if the offices can be placed in towns according to these rules, or NIE (no in Polish) - in the opposite case.
If the answers is TAK, then the following lines should give an exemplary placement of the offices. Thus the line no.
should hold:
the letter K if there should be an office of The Tailors Guild in the town , or the letter S if there should be an office of The Sewers Guild in the town
, or the letter N if there should be no office in the town
.
输入输出样例
7 8
1 2
3 4
5 4
6 4
7 4
5 6
5 7
6 7
TAK
K
S
K
S
K
K
N
思路:可以得到一个结论,只要没有度数为0的点就一定可以。
然后宽搜染色就可以了。
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 500010
using namespace std;
queue<int>que;
int n,m,tot;
int fa[MAXN],col[MAXN],into[MAXN];
int to[MAXN*],net[MAXN*],head[MAXN];
int find(int x){
if(fa[x]==x) return fa[x];
else return fa[x]=find(fa[x]);
}
void add(int u,int v){
to[++tot]=v;net[tot]=head[u];head[u]=tot;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
add(x,y);add(y,x);into[x]++;into[y]++;
int dx=find(x);int dy=find(y);fa[dy]=dx;
}
for(int i=;i<=n;i++)
if(into[i]==){ printf("NIE\n");return ;}
memset(col,-,sizeof(col));
for(int i=;i<=n;i++)
if(fa[i]==i){ que.push(i);col[i]=; }
while(!que.empty()){
int now=que.front();
que.pop();
for(int i=head[now];i;i=net[i])
if(col[to[i]]==-){
col[to[i]]=(col[now]==?:);
que.push(to[i]);
}
}
printf("TAK\n");
for(int i=;i<=n;i++)
if(col[i]==) printf("K\n");
else printf("S\n");
}
洛谷 P3496 [POI2010]GIL-Guilds的更多相关文章
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- [洛谷P3501] [POI2010]ANT-Antisymmetry
洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...
- 洛谷 P3496 BZOJ 2079 [POI2010]GIL-Guilds
题目描述 King Byteasar faces a serious matter. Two competing trade organisations, The Tailors Guild and ...
- 洛谷 P3507 [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解
这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...
- 洛谷P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- [洛谷P3509][POI2010]ZAB-Frog
题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...
- 洛谷 [P3496] BLO
割点 首先 tarjan 求割点, 对于不是割点的点, 答案是 2 * (n-1) 有序,所以要乘 2 对于是割点的点, 答案是删去该点后所有连通块的个数加上 n-1 在乘 2 #include &l ...
随机推荐
- RHEL6.5设置行号,安装GCC
vim ~/.vimrc set nu set cindent set tabstop=4 set shiftwidth=4 syntax on 安装gcc,g++编译器 ...
- dubbo+zookeeper下生产者和消费者配置(基于springboot开发)
一.总共分为三个目录: dubbo-api 服务的接口用于对接客户端和服务端 dubbo-client 客户端配置文件为:consumer.xml dubbo-service 服务 ...
- Linux-fork()函数详解,附代码注释
// // main.c // Project_C // // Created by LiJinxu on 16/8/13. // Copyright © 2016年 LiJinxu-NEU. All ...
- Emoji过滤
private static boolean isNotEmojiCharacter(char codePoint) { return (codePoint == 0x0) || (codePoint ...
- C# 多线程系列(六)
同步 当多个线程共享一些数据的时候,我们就需要使用同步技术,确保一次只有一个线程访问合改变共享状态.注意,同步问题与争用和死锁有关. 例: ; static void Add() { ; i < ...
- 我的github教程
这篇文章记录个人常用的一些命令,和记不住的一些命令. 安装 在 Windows 上安装 Git ,有个叫做 msysGit 的项目提供了安装包: http://msysgit.github.io/ 完 ...
- js中添加node.js语法支持
File——>settings
- Python Base of Scientific Stack(Python基础之科学栈)
Python Base of Scientific Stack(Python基础之科学栈) 1. Python的科学栈(Scientific Stack) NumPy NumPy提供度多维数组对象,以 ...
- SQL练习题_用户购买收藏记录合并(拼多多)
目录 拼多多笔试题0805_统计用户数据 笔试题描述 表格构建 数据观察 题目分析 一.合并表格 二.CASE表示(0,1) 三.同理复制FORK表 题目解答 拼多多笔试题0805_统计用户数据 笔试 ...
- LinearLayout中间布局填充出现的问题
线性布局如何中间填充,会挤掉他下面的布局,所以中间填充使用layout_weight属性.