日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【bzoj1086】 scoi2005—王室联邦

發布時間:2025/7/25 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【bzoj1086】 scoi2005—王室联邦 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://www.lydsy.com/JudgeOnline/problem.php?id=1086?(題目鏈接)

題意

  求將樹分為幾個聯通塊,每個聯通塊大小大于B小于3B,是否可行。

Solution

  題都沒看就翻了題解。。http://blog.csdn.net/popoqqq/article/details/42772237

代碼

// bzoj3757 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #define MOD 1000000007 #define inf 2147483640 #define LL long long #define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout); using namespace std; inline LL getint() {LL x=0,f=1;char ch=getchar();while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}return x*f; }const int maxn=1010; struct edge {int next,to;}e[maxn<<2]; int head[maxn],size[maxn],pos[maxn],q[maxn],n,B,cnt,top,c,cap[maxn];void insert(int u,int v) {e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt; } void dfs(int x,int fa) {q[++top]=x;for (int i=head[x];i;i=e[i].next) if (e[i].to!=fa) {dfs(e[i].to,x);if (size[x]+size[e[i].to]>=B) {size[x]=0;cap[++cnt]=x;while (q[top]!=x) pos[q[top--]]=cnt;}else size[x]+=size[e[i].to];}size[x]++; } void paint(int x,int fa,int c) {if (pos[x]) c=pos[x];else pos[x]=c;for (int i=head[x];i;i=e[i].next) if (e[i].to!=fa) paint(e[i].to,x,c); } int main() {scanf("%d%d",&n,&B);for (int i=1;i<n;i++) {int u,v;scanf("%d%d",&u,&v);insert(u,v);}if (n<B) {printf("0");return 0;}cnt=0;dfs(1,0);if (!cnt) cap[++cnt]=1;paint(1,0,cnt);printf("%d\n",cnt);for (int i=1;i<=n;i++) printf("%d ",pos[i]);printf("\n");for (int i=1;i<=cnt;i++) printf("%d ",cap[i]);return 0; }

  

轉載于:https://www.cnblogs.com/MashiroSky/p/5914607.html

總結

以上是生活随笔為你收集整理的【bzoj1086】 scoi2005—王室联邦的全部內容,希望文章能夠幫你解決所遇到的問題。

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