zoukankan      html  css  js  c++  java
  • 1154 Vertex Coloring (25分)

    看见顶点涂色,还以为要dfs啥的,没想到就是简单模拟,散列表是手动模拟的没用unordered_map

    #include<iostream>
    #include<cstring>
    
    using namespace std;
    
    const int N = 10010, M = 20003;
    
    struct{
        int a, b;
    }edges[N];
    
    int color[N];
    int n, m;
    int st[M], e[M], ne[M], idx;
    
    void insert(int x){
        int k = x % M;
        e[idx] = x, ne[idx] = st[k], st[k] = idx ++;
    }
    
    int find(int x){
        int k = x % M;
        for(int i = st[k]; i != -1; i = ne[i]) if(e[i] == x) return 1;
        return 0;
    }
    
    int main(){
        cin >> n >> m;
        
        for(int i = 1; i <= m; i ++){
            int a, b;
            cin >> a >> b;
            
            edges[i] = {a, b};
        }
        
        int k;
        cin >> k;
        
        while(k --){
            int type = 0;
            memset(st, -1, sizeof st);
            idx = 0;
            for(int i = 0; i < n; i ++){
                int c;
                cin >> c;
                color[i] = c;
                if(!find(c)){
                    insert(c);
                    type ++;
                }
            }
            
            int res = 1;
            for(int i = 1; i <= m; i ++){
                int a = edges[i].a, b = edges[i].b;
                if(color[a] == color[b]){
                    res = 0;
                    break;
                }
            }
            
            if(res) printf("%d-coloring
    ", type);
            else puts("No");
        }
        
        return 0;
    }
    
  • 相关阅读:
    pandas:数据分析
    NumPy(数组计算)
    量化投资与python
    量化投资与python
    vue-cli之脚手架
    pycharm与github的使用
    GIT命令
    关于pytest的命令行传参
    python脚本测试websocket接口协议
    python关于type()与生成器generator的用法
  • 原文地址:https://www.cnblogs.com/tomori/p/13754360.html
Copyright © 2011-2022 走看看