求助模板题
  • 板块题目总版
  • 楼主linxuanrui
  • 当前回复13
  • 已保存回复13
  • 发布时间2023/7/4 18:16
  • 上次更新2023/11/3 11:36:44
查看原帖
求助模板题
857323
linxuanrui楼主2023/7/4 18:16

rt,如你所见,我连模板都不会……

这是一道很显然的图论 + DFS 题,但是……

#pragma GCC optmize(2,3,"Ofast","inline")
#include<bits/stdc++.h>
#define endl '\n'
typedef long long ll;
using namespace std;
int n,s;
int a[21][21],x[21];
bool vis[21];
void dfs(int k){
	if(k == n + 1){
		for(int i = 1;i <= n;i++)cout << x[i] << " ";
		cout << endl;
		exit(0);
	}
	for(int i = 1;i <= 4;i++){
		x[k] = i;
		bool flag = true;
		for(int j = 1;j <= n;j++){
			if(a[k][j] && x[j] == x[k]){
				flag = false;
				break;
			}
		}
		if(flag)dfs(k + 1);
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			cin >> a[i][j];
		}
	}
	dfs(1);
}

我随便构造了一组数据,如下:

5
0 1 1 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 0

这是一个点数为 55 的完全图(?),然后我居然找不到一组合适的解。

所以是 wssb 还是四色定理出错了(

2023/7/4 18:16
加载中...