1154 Vertex Coloring (25分)

本文探讨了图论中的k-着色问题,即如何使用最多k种颜色为图的顶点上色,使得任意两个相邻顶点颜色不同。通过输入图的顶点数、边数以及具体的边连接信息,结合一组给定的颜色方案,算法能够判断这些方案是否构成正确的k-着色。文章详细介绍了实现这一判断的BFS遍历算法,并提供了完整的C++代码示例。

proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring.

Now you are supposed to tell if a given coloring is a proper k-coloring.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers Nand M (both no more than 10​4​​), being the total numbers of vertices and edges, respectively. Then M lines follow, each describes an edge by giving the indices (from 0 to N−1) of the two ends of the edge.

After the graph, a positive integer K (≤ 100) is given, which is the number of colorings you are supposed to check. Then K lines follow, each contains N colors which are represented by non-negative integers in the range of int. The i-th color is the color of the i-th vertex.

Output Specification:

For each coloring, print in a line k-coloring if it is a proper k-coloring for some positive k, or No if not.

Sample Input:

10 11
8 7
6 8
4 5
8 4
8 1
1 2
1 4
9 8
9 1
1 0
2 4
4
0 1 0 1 4 1 0 1 3 0
0 1 0 1 4 1 0 1 0 0
8 1 0 1 4 1 0 5 3 0
1 2 3 4 5 6 7 8 8 9

Sample Output:

4-coloring
No
6-coloring
No

#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int n, m;
vector<int> vec(n);
vector<bool> visit;
vector<int> vec_graph[10009];
//int graph[10001][10001] = {0};
set<int> set_k;
bool BFS(int start){
    queue<int> q;
    visit[start] = true;
    q.push(start);

   

    while (!q.empty())
    {
        start = q.front();
        q.pop();
        for(int z = 0; z < vec_graph[start].size(); z++){
            if(vec[start] == vec[vec_graph[start][z]])
                 
                 return false;
            if(!visit[vec_graph[start][z]]){

                visit[vec_graph[start][z]] = true;
                q.push(vec_graph[start][z]);
                
 
            }


        }
        
    }
    
   

    return true;

}

int main(){



    cin >> n >> m;
//    memset(graph, 0, sizeof(graph));
    for(int i = 0; i < m; i++){

        int temp_x , temp_y;
        scanf("%d %d", &temp_x, &temp_y);
//        cin >> temp_x >> temp_y;
        vec_graph[temp_x].push_back(temp_y);
//        vec_graph[temp_y].push_back(temp_x);
//        graph[temp_x][temp_y] = graph[temp_y][temp_x] = 1;

    }
    
    int k;
    scanf("%d", &k);

    for(int i = 0; i < k; i++){
//        bool visit[10001] = {false};
        visit.clear();
        vec.clear();
        set_k.clear();
        bool flag = true;
        for(int j = 0; j < n; j++){
            int temp;
            
            scanf("%d", &temp);

            vec.push_back(temp);
            set_k.insert(temp);
            visit.push_back(false);

        }
        for(int start = 0; start < n; start++){

            if(!visit[start])
                if(!BFS(start)){
                    
                    flag = false;
                    break;
                }


        }


        if(flag){
            cout << set_k.size() << "-coloring" << endl;
//            printf("%lu-coloring\n", set_k.size());

        }else
        {
            printf("No\n");
        }
        


    }



    return 0;
}

 

基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究”展开,提出了一种结合数据驱动方法与Koopman算子理论的递归神经网络(RNN)模型线性化方法,旨在提升纳米定位系统的预测控制精度与动态响应能力。研究通过构建数据驱动的线性化模型,克服了传统非线性系统建模复杂、计算开销大的问题,并在Matlab平台上实现了完整的算法仿真与验证,展示了该方法在高精度定位控制中的有效性与实用性。; 适合人群:具备一定自动化、控制理论或机器学习背景的科研人员与工程技术人员,尤其是从事精密定位、智能控制、非线性系统建模与预测控制相关领域的研究生与研究人员。; 使用场景及目标:①应用于纳米级精密定位系统(如原子力显微镜、半导体制造设备)中的高性能预测控制;②为复杂非线性系统的数据驱动建模与线性化提供新思路;③结合深度学习与经典控制理论,推动智能控制算法的实际落地。; 阅读建议:建议读者结合Matlab代码实现部,深入理解Koopman算子与RNN结合的建模范式,重点关注数据预处理、模型训练与控制系统集成等关键环节,并可通过替换实际系统数据进行迁移验证,以掌握该方法的核心思想与工程应用技巧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值