日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

[模板]黑白染色

發布時間:2025/5/22 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [模板]黑白染色 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如題:模板保存。

#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const int maxn=1e5+5; const int maxm=1e5+5;int c[maxn]; //color,每個點的黑白屬性,-1表示還沒有標記,0/1表示黑白,比vis數組多一個作用 int num[2]; //在一次DFS中的黑白點個數 bool f=0; //判斷是否出現奇環int head[maxn],tot,n,m; struct edge{int to;int nxt; }e[maxm]; void add_edge(int u,int v){e[tot].to=v;e[tot].nxt=head[u];head[u]=tot++; } void init(){memset(head,-1,sizeof head);tot=0;memset(c,-1,sizeof c); }void dfs(int u,int x){if(f)return;c[u]=x;num[x]++;for(int i=head[u];~i;i=e[i].nxt){int j=e[i].to;if(c[j]==-1) dfs(j,!x);else if(c[j]==x){//沖突了,不沖突則跳過。f=1;return;}} } int main(){for(int i=1;i<=n&&(!f);i++){if(c[i]==-1){num[0]=num[1]=0;dfs(i,1);}} }

?

轉載于:https://www.cnblogs.com/elpsycongroo/p/10356610.html

總結

以上是生活随笔為你收集整理的[模板]黑白染色的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。