PAT-1154(Vertex Coloring )+map使用+vector建图+set的使用
Vertex Coloring
PAT-1154
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<unordered_map>
using namespace std;
const int maxn=10004;
int n,m;
vector<int>ve[maxn];
int colo[maxn];
int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
ve[a].push_back(b);
ve[b].push_back(a);
}
int k;
cin>>k;
while(k--){
set<int>se;
for(int j=0;j<n;j++){
cin>>colo[j];
se.insert(colo[j]);
}
int numk=0;
bool flag=true;
for(int j=0;j<n;j++){
int acolor=colo[j];
for(auto item:ve[j]){
int b=item;
int bcolor=colo[b];
if(bcolor==acolor){
flag=false;
break;
}
}
if(!flag)
break;
}
if(flag){
cout<<se.size()<<"-coloring"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
}
PAT-1154(Vertex Coloring )+map使用+vector建图+set的使用的更多相关文章
- PTA 1154 Vertex Coloring
题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...
- PAT 甲级 1154 Vertex Coloring
https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...
- pat甲级 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- PAT Advanced 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- PAT Advanced 1154 Vertex Coloring (25) [set,hash]
题目 A proper vertex coloring is a labeling of the graph's vertices with colors such that no two verti ...
- 1154 Vertex Coloring
题目前半略 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 ...
- PAT A1134 Vertex Cover (25 分)——图遍历
A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...
- Dijkstra算法堆优化(vector建图)
#include<iostream> #include<algorithm> #include<string.h> #include<stdio.h> ...
- zzulioj--1831-- 周末出游(vector建图+dfs)
1831: 周末出游 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 22 Solved: 8 SubmitStatusWeb Board Descr ...
随机推荐
- 2019牛客多校 Round1
Solved:4 Rank:143 A Equivalent Prefixes 题意:求一个最大的r满足在A,B两个数组中1,r里所有的子区间RMQ相等 题解:单调队列秒 #include <b ...
- 【noi 2.6_8786】方格取数(DP)
题意:N*N的方格图每格有一个数值,要求从左上角每步往右或往下走到右下角,问走2次的最大和. 解法:走一次的很好想,而走2次,不可误以为先找到最大和的路,再找剩下的最大和的路就是正解.而应该认清动态规 ...
- Atcoder Panasonic Programming Contest 2020
前三题随便写,D题是一道dfs的水题,但当时没有找到规律,直接卡到结束 A - Kth Term / Time Limit: 2 sec / Memory Limit: 1024 MB Score ...
- 洛谷 P1429 平面最近点对(加强版) (分治模板题)
题意:有\(n\)个点对,找到它们之间的最短距离. 题解:我们先对所有点对以\(x\)的大小进行排序,然后分治,每次左右二等分递归下去,当\(l+1=r\)的时候,我们计算一下距离直接返回给上一层,若 ...
- 牛客编程巅峰赛S1第5场 - 黄金&钻石&王者 B.牛牛的字符串 (DP)
题意:有一个字符串\(s\),我们可以选择\(s_{i}\),如果\(s_{i+k}>s_{i}\),那么就可以交换\(s_{i}\)和\(s_{i+k}\),问最多能够交换多少次. 题解:因为 ...
- Cell 动态行高文字显示不全问题探索
目录 问题概述 一.新建工程 二.尝试复现问题 尝试解决 修改contentLblBtmCon优先级为High(750) 修改contentLblBtmCon优先级为Low(250) 小结 其他解决思 ...
- 在.NET中体验GraphQL
前言 以前需要提供Web服务接口的时候,除了标准的WEBAPI形式,还考虑了OData.GraphQL等形式,虽然实现思路上有很大的区别,但对使用方来说,都是将查询的主动权让渡给了前端,让调用方能够更 ...
- 国内centos/windows10安装minikube
centos/windows10安装minikube 目录 centos/windows10安装minikube A win10安装minikube 1 下载安装kubectl.exe 1.1 准备目 ...
- codefoeces 864B
B. Polycarp and Letters time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 12.tomcat7切换tomcat8导致cookie异常
一.现象 换成Tomcat8后出现cookie报错 二.分析 经异常去查看源码发现,Tomcat8对cookie校验规则改变,更为严格的校验了cookieHeader不允许有, 日志中的[XXXXX, ...