题目描述

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. hdu1814Peaceful Commission(2-SAT)

    Peaceful Commission Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  2. [Swift通天遁地]七、数据与安全-(8)创建普通PDF文档和加密PDF文档

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. 2019 年了,为什么我还在用 jQuery?

    译者按: 看来 jQuery 还是有一些用武之地的. 原文: Why I'm Still Using jQuery in 2019 译者: Fundebug 为了保证可读性,本文采用意译而非直译.翻译 ...

  4. Offer收割_4

    1.水题 2.BFS宽搜(使用优先队列priority_queue) 4.题意:给数组a.要求重排列数组,使得数组中的任意相邻的两个元素不同.如果存在多个方案,那么选择字典序最小的方案.  如果不能满 ...

  5. kubernetes installing and using 单机版

    centos安装docker uname -r yum remove docker \ docker-client \ docker-client-latest \ docker-common \ d ...

  6. Struts2之一 初体验

    Struts2 框架是基于MV模式开发的,它提供了一个核心控制器,用于对所有的请求进行统一处理,这个控制器是由一个名为FilterDispatcher的Servlet过滤器来充当的. 01.需要在we ...

  7. 将子节点的所有父节点ID合并成一个字符串,并更新表

    begin for cur_dept in (select SLCATALOG_ID from T_GIS_SLCATALOG) loop UPDATE T_GIS_SLCATALOG SET PAT ...

  8. 一个数据去重sql

    参考: https://www.jb51.net/article/129656.htm DELETE testcaseFROM testcase,  (  SELECT  max(id) id,  a ...

  9. mysql zip版本如何安装

    1.下载mysqlzip包并解压到D:\javadeveloper\mysql-5.6.24-winx642.配置环境变量在path中添加路径 D:\javadeveloper\mysql-5.6.2 ...

  10. ngFor 循环带索引

    *ngFor="let item of userList,let i = index"   或者 *ngFor="let item of userList index a ...