javaee论坛

普通会员

225648

帖子

332

回复

346

积分

楼主
发表于 2019-10-31 13:24:53 | 查看: 112 | 回复: 1

A propervertexcoloring isalabelingofthegraph'sverticeswithcolorssuchthatnotwoverticessharingthesameedgehavethesamecolor.Acoloringusingatmost k colorsiscalleda(proper) k-coloring.

Nowyouaresupposedtotellifagivencoloringisaproper k-coloring.

InputSpecification:

Eachinputfilecontainsonetestcase.Foreachcase,thefirstlinegivestwopositiveintegers N and M (bothnomorethan 10​4​​),beingthetotalnumbersofverticesandedges,respectively.Then M linesfollow,eachdescribesanedgebygivingtheindices(from0to N−1)ofthetwoendsoftheedge.

Afterthegraph,apositiveinteger K (≤ 100)isgiven,whichisthenumberofcoloringsyouaresupposedtocheck.Then K linesfollow,eachcontains N colorswhicharerepresentedbynon-negativeintegersintherangeof int.The i-thcoloristhecolorofthe i-thvertex.

OutputSpecification:

Foreachcoloring,printinaline k-coloring ifitisaproper k-coloringforsomepositive k,or No ifnot.

SampleInput:1011876845848112149891102440101410130010141010081014105301234567889SampleOutput:4-coloringNo6-coloringNo数据结构:vector<vector<int>>;(因为没有权值) 存边

vector<int>存颜色

#include<iostream>#include<string>#include<sstream>#include<vector>#include<algorithm>#include<cmath>#include<map>usingnamespacestd;//11:50图论intmain(){freopen("C:\\Users\\chenzhuo\\Desktop\\in.txt","r",stdin);intn,m;cin>>n>>m;vector<vector<int>>tmp(n);for(inti=0;i<m;i++){inta,b;cin>>a>>b;tmp[a].push_back(b);}intk;cin>>k;for(inti=0;i<k;i++){vector<int>col(n);intflag=1;intnum=0;//颜色数量map<int,int>mp;for(intj=0;j<n;j++){cin>>col[j];if(mp[col[j]]!=1){num++;mp[col[j]]=1;}}for(intj=0;j<n;j++)//遍历n个顶点{for(autod:tmp[j])//对于每个顶点{if(col[j]==col[d]){cout<<"No"<<endl;flag=0;break;}}if(flag==0){break;}}if(flag==1)//输出{cout<<num<<"-coloring"<<endl;}}}

 


普通会员

0

帖子

300

回复

308

积分
沙发
发表于 2023-01-30 09:15:56

我喜欢

您需要登录后才可以回帖 登录 | 立即注册

触屏版| 电脑版

技术支持 历史网 V2.0 © 2016-2017