题目描述

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 ![](http://main.edu.…

输出格式:

Your program should print out one word in the first line of the standard output:

TAK (yes in Polish) - 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 .

输入输出样例

输入样例#1: 复制

7 8
1 2
3 4
5 4
6 4
7 4
5 6
5 7
6 7
输出样例#1: 复制

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

  1. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  2. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  3. 洛谷 P3496 BZOJ 2079 [POI2010]GIL-Guilds

    题目描述 King Byteasar faces a serious matter. Two competing trade organisations, The Tailors Guild and ...

  4. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  5. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  6. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  7. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  8. [洛谷P3509][POI2010]ZAB-Frog

    题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...

  9. 洛谷 [P3496] BLO

    割点 首先 tarjan 求割点, 对于不是割点的点, 答案是 2 * (n-1) 有序,所以要乘 2 对于是割点的点, 答案是删去该点后所有连通块的个数加上 n-1 在乘 2 #include &l ...

随机推荐

  1. PCB C# MongoDB 查询(SQL,NOSQL,C#对比)

    一.准备阶段 1.查询数据清单准备 2.这里先将SQL语句执行顺序列出来,方便后面语句对比更好理解 ()SELECT ()DISTINCT ()<Top Num> <select l ...

  2. Java基础学习经验分享

    很多人学习Java,尤其是自学的人,在学习的过程中会遇到各种各样的问题以及难点,有时候卡在一个点上可能需要很长时间,因为你在自学的过程中不知道如何去掌握和灵活运用以及该注意的点.下面我整理了新手学习可 ...

  3. 我的周记1——”云想衣裳花想容"

    这里记录过去一周,我学习到的,思考的,看到的,每周五发布. http 网上参考http入门协议  https://juejin.im/post/5afad7f16fb9a07abf72ac30 超文本 ...

  4. 最容易理解的CSS的position教程——十步图解CSS的position

    CSS的positon,我想做为一个Web制作者来说都有碰到过,但至于对其是否真正的了解呢?那我就不也说了,至少我自己并不非常的了解其内核的运行.今天在Learn CSS Positioning in ...

  5. checkbox与文字混排无法对齐到一行的解决办法

    直接上代码: <span><input style="vertical-align:middle" type="checkbox" name= ...

  6. sql server 数据分析优化实战(一)——SQL语句优化

    前言 在我们进行数据分析的时候,首要的目标是根据业务逻辑,通过编写SQL代码得到我们想要的结果,这是毋庸置疑的.一般情况下,由于我们分析的数据量比较少,体会不出SQL语句各种写法的性能优劣,对SQL代 ...

  7. html5——语义标签

    传统布局 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  8. dubbo之并发控制

    并发控制 配置样例 样例 1 限制 com.foo.BarService 的每个方法,服务器端并发执行(或占用线程池线程数)不能超过 10 个: <dubbo:service interface ...

  9. (转)Hibernate关联映射——一对多(多对一)

    http://blog.csdn.net/yerenyuan_pku/article/details/70152173 Hibernate关联映射——一对多(多对一) 我们以客户(Customer)与 ...

  10. http通信流程

    Host https://www.charlesproxy.com Path / Notes SSL Proxying not enabled for this host. Enable in the ...