首页 > 其他分享 >Knights of the Round Table

Knights of the Round Table

时间:2022-11-28 21:12:21浏览次数:46  
标签:int 圆桌会议 ## maxn Table Knights 骑士 include Round




# Description
给定若干骑士和他们之间的仇恨关系,规定召开圆桌会议时,两个有仇恨的骑士不能坐在相邻位置,且召开一次圆桌会议的骑士人数必须为奇数,求有多少骑士永远不可能参加某一次圆桌会议。

# Format

## Input
多组数据,每组数据先给出N,M代表N个骑士和M组关系

接下来M行,每行两个数字

整个测试以0 0结束

1 ≤ n ≤ 1000

1 ≤ m ≤ 1000000

## Output
如题

# Samples

```input1
5 5
1 4
1 5
2 5
3 4
4 5
0 0
```

```output1
2
```

 

 

 

 

#include <iostream>
#include <queue>
#include <stdio.h>
#include <cstring>
#include <vector>
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
using namespace std;
vector<int> g[maxn];
int gg[maxn][maxn];
int dfn[maxn], low[maxn], vis[maxn], Stack[maxn], inStack[maxn];
int color[maxn];
int len, cnt, ts;
int n, m;
void init(int n) 
{
	len = cnt = ts = 0;
	for (int i = 1; i <= n; ++i) g[i].clear();
	fill(vis, vis+n+1, 0);
	fill(dfn, dfn+n+1, 0);
	fill(gg[0], gg[0]+maxn*maxn, 0);
}
int check() {
	fill(color, color+maxn, -1);
	queue<int> que;
	for (int i = 1; i <= n; ++i) 
	{
		if (inStack[i]) 
		{
			que.push(i);
			color[i] = 0;
			break;
		}
	}
	while (!que.empty()) {
		int u = que.front();
		que.pop();
		for (int i = 0; i < (int)g[u].size(); ++i) {
			int v = g[u][i];
			if (inStack[v] == 0) continue;
			if (color[v] == -1) {
				color[v] = color[u] ^ 1;
				que.push(v);
			} else if (color[v] == color[u]) return 1;
		}
	}
	return 0;
}
void tarjan(int u, int fa) 
{
	dfn[u] = low[u] = ++ts;
	Stack[len++] = u;
	for (int i = 0; i < (int)g[u].size(); ++i) {
		int v = g[u][i];
		if (v == fa) continue;
		if (!dfn[v]) {
			tarjan(v, u);
			low[u] = min(low[u], low[v]);
			if (dfn[u] <= low[v]) 
			{
				fill(inStack, inStack+n+1, 0);
				inStack[u] = 1;
				while (1) {
					int top = Stack[--len];
					inStack[top] = 1;
					if (top == v) break;
				}
				if (check()) 
				{
					for (int i = 1; i <= n; ++i) 
					{
						if (inStack[i])
							vis[i] = 1;
					}
				}
			}
		} else low[u] = min(low[u], dfn[v]);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	while (scanf("%d %d", &n, &m), n) {
		init(n);
		for (int i = 0; i < m; ++i) {
			int u, v;
			scanf("%d%d", &u, &v);
			gg[u][v] = gg[v][u] = 1;
		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				if (i == j || gg[i][j])
					continue;
				g[i].push_back(j);
			}
		}
		for (int i = 1; i <= n; ++i) {
			if (dfn[i]) continue;
			tarjan(i, 0);
		}
		int ans = n;
		for (int i = 1; i <= n; ++i)
			ans -= vis[i];
		printf("%d\n", ans);
	}
	return 0;
}

 

标签:int,圆桌会议,##,maxn,Table,Knights,骑士,include,Round
From: https://www.cnblogs.com/cutemush/p/16933619.html

相关文章

  • Codeforces Round #829 (Div. 1) C
    C.WishIKnewHowtoSort我们会发现此题的终点状态只有一个起点状态也只有一个所以我们的状态表示可以非常简单我们可以发现我们为了达到最终的状态我们用一些1来......
  • Oracle中ALTER TABLE的五种用法(三)
    首发微信公众号:SQL数据库运维原文链接:https://mp.weixin.qq.com/s?__biz=MzI1NTQyNzg3MQ==&mid=2247485212&idx=1&sn=450e9e94fa709b5eeff0de371c62072b&chksm=ea37536cdd......
  • Electron-vue 使用Element-UI el-table 不显示
    在Electron-Vue中引入Element-UI,发现el-table显示空白,查资料发现只需要在.electron-vue/webpack.renderer.config里面白名单模块加上 'element-ui'  //修改前......
  • Immutable(不可变)集合
    不可变集合,顾名思义就是说集合是不可被修改的。集合的数据项是在创建的时候提供,并且在整个生命周期中都不可改变。为什么要用immutable对象?immutable对象有以下的优点:对不可......
  • 别再把Tableau、PowerBI吹上天了,国内根本用不起来,看看为啥
    工作业务相关,这几年接触BI较多,借此浅聊下我对BI工具以及市场的看法,原创禁止转载。1、BI并不玄乎,本质就是实现简单数据分析和可视化的工具很多人觉得BI玄乎,其实很大程度是因......
  • SAP UI5 SmartTable 控件的使用介绍试读版
    本文来自笔者SAP开发技术交流知识星球内一位朋友的提问:smartfilterbar有个输入框CostElement绑定了cds实现valuehelp请问其对应的suggestion功能是通过cds的注解实现......
  • itextpdf5 com.itextpdf.text.PdfPTable
    com.itextpdf.text.PdfPTableDemo注意:表格中的列必须填满,否则表格不显示。PdfPTabletable=newPdfPTable(3)//设置表格的填充宽度百分比,在当前Table和其父级......
  • Codeforces Round #828 (Div. 3) F
    F.MEXvsMED一开始写了个感觉每个点只会搞一次的那种线性感性理解了很对结果又wa又tintleft=l-z-1,right=n-r;intcnt=2*now;for(intle......
  • SAP UI5 表格数据如何导出成 Excel 文件(Table Export As Excel)
    本教程前一步骤,我们在介绍SAPUI5SmartTable时,提到了它的Excel导出功能。如果将iseExportToExcel设置为true,就可以启用Excel导出功能,将Table控件显示的数据,导......
  • SAP UI5 Table 控件数据进行 Excel 导出时如何进行格式控制试读版
    本教程的前一步骤,我们成功的将sap.m.Table控件里显示的数据导出到了本地Excel文件中。下图是使用sap.m.Table显示的表格页面:下面是点击上图右上角Excel导出按钮......