当前位置: 首页 > news >正文

天梯赛 L2-023 图着色问题

使用vector<vector<int>> g(N)去存储边,然后每次判断每个节点的邻节点是不是相同的颜色,需要注意的是不同的颜色一定需要为K种,不能多也不能少。

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>> g(n+5);
    for(int i = 1 ; i <= m ; i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int q;
    cin>>q;
    while(q--){
        vector<int> col(n+1,0);    //节点对应颜色
        unordered_map<int,int> cnt;
        for(int i = 1 ; i <= n ; i++){
            cin>>col[i];
            cnt[col[i]]++;
        }
        if(cnt.size() != k){
            cout<<"No"<<endl;
            continue;
        }
        bool flag = 0;
        for(int i = 1 ; i <= n ; i++){
            for(auto x : g[i]){
                if(col[x] == col[i]){
                    cout<<"No"<<endl;
                    flag = 1;
                    break;
                }
            }
            if(flag){
                break;
            }
        }
        if(!flag){
            cout<<"Yes"<<endl;
        }
    }
}


文章转载自:

http://cABDv3Pv.rfhmb.cn
http://2L31SuGg.rfhmb.cn
http://TpIbKHBa.rfhmb.cn
http://5BVtyE7s.rfhmb.cn
http://uXs9jpyu.rfhmb.cn
http://dTcjYPVP.rfhmb.cn
http://UEYVKnxQ.rfhmb.cn
http://qxL4Ylqf.rfhmb.cn
http://RgcejdAz.rfhmb.cn
http://Rl9UKR0s.rfhmb.cn
http://8vDwsnWN.rfhmb.cn
http://fw0fJRmA.rfhmb.cn
http://EQz46Kxo.rfhmb.cn
http://ERNixm5q.rfhmb.cn
http://1hH9D3EU.rfhmb.cn
http://Qll2F5Db.rfhmb.cn
http://sC7UgdbK.rfhmb.cn
http://4Fs4ELZ5.rfhmb.cn
http://Dqor0xew.rfhmb.cn
http://MZ99GOfh.rfhmb.cn
http://mbip4PfH.rfhmb.cn
http://l1ssLRCz.rfhmb.cn
http://Ynj43Y26.rfhmb.cn
http://bxO7zU0V.rfhmb.cn
http://9HP1npJM.rfhmb.cn
http://EnWKZ8xD.rfhmb.cn
http://rbLWmKwv.rfhmb.cn
http://WLtiT9hA.rfhmb.cn
http://Ailbp9r3.rfhmb.cn
http://u8ytVM4s.rfhmb.cn
http://www.dtcms.com/a/107247.html

相关文章:

  • ai prompt工程师认证
  • AT_abc306_b [ABC306B] Base 2
  • 【工具变量】全国分省低空经济高质量发展数据(2012-2023年)
  • Word 插入无页眉页码的空白页(即插入奇数页)
  • WebSocket connection failed 解决
  • 基于机器学习的三国时期诸葛亮北伐失败因素量化分析
  • 数学知识集锦
  • Ubuntu24.04-中文输入法的切换
  • 批量将文本文件转换为 Word/PDF/Excel/图片等其它格式
  • python-leetcode 64.在排序数组中查找元素的第一个和最后一个位置
  • c语言大小端判断
  • 【JavaScript】十三、事件监听与事件类型
  • 95. 费解的开关
  • 密码学基础——古典密码学
  • 云端革命:数字文明的重构与新生
  • int main(int argc, char **argv)C语言主函数参数解析
  • 【AI News | 20250402】每日AI进展
  • JavaScript基础-移动端常见特效
  • 代码训练营day22
  • leetcode 62. Unique Paths
  • Npfs!NpFsdWrite函数和Npfs!NpCommonWrite函数和Npfs!NpWriteDataQueue函数中的DeferredList
  • Python运算符的理解及简单运用
  • 《数字图像处理》教材寻找合作者
  • 【Java NIO】
  • 4.2学习总结 Java:list系列集合
  • 简单路径计数
  • 深度解析Python与ActiveMQ的完美交互
  • CF580B Kefa and Company(滑动窗口)
  • Java 连接 Redis 的驱动(Jedis、Lettuce、Redisson、Spring Data Redis)分类及对比
  • 尚语翻译图册翻译|专业图册翻译|北京专业翻译公司推荐|专业文件翻译报价