CF741C Arpa’s overnight party and Mehrdad’s silent entering
Posted cjoiershiina-mashiro
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF741C Arpa’s overnight party and Mehrdad’s silent entering相关的知识,希望对你有一定的参考价值。
Link
显然是二分图染色,情侣之间不同色直接一条边就行了。
而要连续的三个人不全同色,可以要求((2i-1,2i))这两人不同色,这样一定满足连续的三人不全同色。
冷静分析发现这张图显然没有奇环,所以一定有解。
#include<cstdio>
#include<cctype>
#include<vector>
#include<utility>
namespace IO
{
char ibuf[(1<<21)+1],obuf[(1<<21)+1],st[15],*iS,*iT,*oS=obuf,*oT=obuf+(1<<21);
char Get(){return (iS==iT? (iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT? EOF:*iS++)):*iS++);}
void Flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf;}
void Put(char x){*oS++=x;if(oS==oT)Flush();}
int read(){int x=0,c=Get();while(!isdigit(c))c=Get();while(isdigit(c))x=x*10+c-48,c=Get();return x;}
void write(int x,char c){int top=0;if(!x)Put('0');while(x)st[++top]=(x%10)+48,x/=10;while(top)Put(st[top--]);Put(c);}
}using namespace IO;
const int N=200007;
std::vector<int>e[N];int col[N];std::pair<int,int>a[N];
void dfs(int u){for(int v:e[u]) if(!col[v]) col[v]=3-col[u],dfs(v);}
int main()
{
int n=read();
for(int i=1,u,v;i<=n;++i) u=read(),v=read(),a[i]={u,v},e[u].push_back(v),e[v].push_back(u);
for(int i=1;i<=n*2;i+=2) e[i].push_back(i+1),e[i+1].push_back(i);
for(int i=1;i<=n*2;++i) if(!col[i]) col[i]=1,dfs(i);
for(int i=1;i<=n;++i) write(col[a[i].first],' '),write(col[a[i].second],'
');
Flush();
}
以上是关于CF741C Arpa’s overnight party and Mehrdad’s silent entering的主要内容,如果未能解决你的问题,请参考以下文章
CF741E Arpa’s abnormal DNA and Mehrdad’s deep interest
CF741B Arpa's weak amphitheater and Mehrdad's valuable Hoses 并查集 01背包
CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
CF741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
「CF741D」Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths