蓝桥训练 分考场
发布日期:2021-05-14 16:48:41 浏览次数:10 分类:精选文章

本文共 2142 字,大约阅读时间需要 7 分钟。

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������������������������DFS���������������������������������������������������������������������������������������������������������������������������������������������������������������

#include 
#include
#include
#include
#include
using namespace std;
void dfs(int x, int group, vector
>& adj, vector
>& color, int color_num, int& res) { if (x == color_num) { //������������������������ return; } for (int i = 1; i <= color_num; ++i) { if (color[i] == -1) { //��������������������� bool success = true; for (int v : adj[x]) { //������������������������ if (color[v] == i) { //��������������������� success = false; break; } } if (success) { //������������������������������ color[i] = x; //������������������������i res = min(res, color_num); //��������������������������� dfs(v, color_num + 1, adj, color, color_num, res); color[i] = -1; //��������������������������������������������������������������� } } } } int main() { //������������ vector
> adj(n + 1); fill(adj.begin(), adj.begin(), -1); m = 0; for (int i = 1; i <= n; ++i) { adj[i] = vector
(); } for (int i = 1; i <= m; ++i) { a, b = Mendfelt������������ if (a > b) swap(a, b); adj[a].push_back(b); adj[b].push_back(a); } //��������������������� int color_num = 0; vector
color(color_num + 1, -1); //���������0���color_num int res = n; for (int x = 1; x <= n; ++x) { //���������x������������������������ dfs(x, 1, adj, color, color_num, res); } cout << res << endl; }

���������������DFS������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:蓝桥训练 ,判断两个点是否连通
下一篇:最小生成树 acwing1146. 新的开始

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月14日 11时20分52秒