题目描述

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. JS属性defer

      其实就是简单的利用defer属性,让浏览器读JS脚本的时候完全不等脚本开始读就开始读下面的图片啊,html代码了.然后让js脚本自己在那里慢慢读取完以后再执行. 给外链的js脚本添加defer=& ...

  2. Visual Studio Code配置GitHub(Win7环境)

    一.软件环境说明(演示环境) 1.操作系统:Windows7旗舰版(64bit) 2.Visual Studio Code版本:1.32.3 3.Git版本:2.21.0.windows.1 二.软件 ...

  3. 题解报告:poj 3070 Fibonacci

    题目链接:http://poj.org/problem?id=3070 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, a ...

  4. Android项目实战_手机安全卫士进程管理

    ###1.设备进程信息获取获取设备运行进程 ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVI ...

  5. Angular——自定义指令

    基本介绍 有了很多内置指令,但是依然无法满足我们的需要,我们可以自己定义一个指令,实现默写功能. 基本使用 directive方法可以帮助我们自己定义一个指令,它的返回方式一共有四种,ECMA,代表所 ...

  6. jQuery——stop

    为什么要停止动画? 对同一个元素,如果拥有一个以上的动画对其加以作用,那么后面的动画会被放入一个动画队列中.动画队列的动画是在其上一个动画完成以后才会执行. 控制两个参数四种情况 1.第一个参数表示后 ...

  7. ASP.NET 缓存(Cache)

    ASP.NET提供了在一个ASP.NET应用程序基本上缓存信息的编程功能.该功能和Application对象相似,但它具有在ASP.NET应用程序的生命周期内动态维护缓存信息的能力.在应用程序中缓存数 ...

  8. iframe监听unload事件

    阻止默认事件 event.preventDefault(); 阻止事件冒泡 event.stopPropagation(); event.cancelBubble = true; //IE <a ...

  9. haproxy故障处理

    1. haproxy 在配置健康检查的时候,默认没有配置页面检查 ,通过端口状态来检测.后端IIS web服务开始可能 是一个站点,或者采用了基于域名的配置方式,导致目前站点停了,后端主机不能被hap ...

  10. HDU_1542_线段树【扫描线】

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...