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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【BZOJ2625】[Neerc2009]Inspection 最小流

發布時間:2025/7/14 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【BZOJ2625】[Neerc2009]Inspection 最小流 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【BZOJ2625】[Neerc2009]Inspection

Description

You are in charge of a team that inspects a new ski resort. A ski resort is situated on several mountains and consists of a number of slopes. Slopes are connected with each other, forking and joining. A map of the ski resort is represented as an acyclic directed graph. Nodes of the graph represent different points in ski resort and edges of the graph represent slopes between the points, with the direction of edges going downwards.?
Your team has to inspect each slope of the ski resort. Ski lifts on this resort are not open yet, but you have a helicopter. In one fiight the helicopter can drop one person into any point of the resort. From the drop off point the person can ski down the slopes, inspecting each slope as they ski. It is fine to inspect the same slope multiple times, but you have to minimize the usage of the helicopter. So, you have to figure out how to inspect all the slopes with the fewest number of helicopter flights. 給張有向無環圖,問至少多少條路徑能夠覆蓋所有的邊(可以重復

Input

The first line of the input file contains a single integer number n (2 <= n <= 100) - the number of points in the ski resort. The following n lines of the input file describe each point of the ski resort numbered from 1 to n. Each line starts with a single integer number mi (0 <= mi < n for i from 1 to n) and is followed by mi integer numbers aij separated by spaces. All aij are distinct for each i and each aij (1 <= aij <= n, aij??i) represents a slope going downwards from point i to point aij . Each point in the resort has at least one slope connected to it.

Output

On the first line of the output file write a single integer number k - the minimal number of helicopter flights that are needed to inspect all slopes. Then write k lines that describe inspection routes for each helicopter flight. Each route shall start with single integer number from 1 to n - the number of the drop off point for the helicopter flight, followed by the numbers of points that will be visited during inspection in the corresponding order as the slopes are inspected going downwards. Numbers on a line shall be separated by spaces. You can write routes in any order.

Sample Input

8
1 3
1 7
2 4 5
1 8
1 8
0
2 6 5
0

Sample Output

4

題解:經典的最小鏈覆蓋問題。

采用有上下界的網絡流的思路,將每個點拆成兩個,從出點向入點連一條(0,inf)的邊,對于每條邊(a,b)從a的出點向b的入點連一條(1,inf)的邊。然后先跑可行流再反著跑最大流。但是發現一個性質,第一遍跑可行流時一定能夠滿流,所以我們直接跑第二遍即可,具體連邊方法:

1.S->每個點的出點,每個點的入點->T 容量inf
2.每個點的入點->出點 容量inf
3.對于(a,b),a的出點->b的入點 容量inf,a的出點->S,b的入點->T 容量1

ans=m-從T到S的最大流

#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std; const int inf=1<<30; int n,m,S,T,cnt,ans; int to[100000],next[100000],val[100000],head[1000],d[1000],m1[1000],m2[1000]; queue<int> q; int rd() {int ret=0,f=1; char gc=getchar();while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}while(gc>='0'&&gc<='9') ret=ret*10+gc-'0',gc=getchar();return ret*f; } void add(int a,int b,int c,int d) {to[cnt]=b,val[cnt]=c,next[cnt]=head[a],head[a]=cnt++;to[cnt]=a,val[cnt]=d,next[cnt]=head[b],head[b]=cnt++; } int dfs(int x,int mf) {if(x==T) return mf;int i,k,temp=mf;for(i=head[x];i!=-1;i=next[i]){if(d[to[i]]==d[x]+1&&val[i]){k=dfs(to[i],min(temp,val[i]));if(!k) d[to[i]]=0;val[i]-=k,val[i^1]+=k,temp-=k;if(!temp) break;}}return mf-temp; } int bfs() {while(!q.empty()) q.pop();memset(d,0,sizeof(d));int i,u;q.push(S),d[S]=1;while(!q.empty()){u=q.front(),q.pop();for(i=head[u];i!=-1;i=next[i]){if(!d[to[i]]&&val[i]){d[to[i]]=d[u]+1;if(to[i]==T) return 1;q.push(to[i]);}}}return 0; } int main() {n=rd(),S=0,T=2*n+1;int i,a,b;memset(head,-1,sizeof(head));for(i=1;i<=n;i++){a=rd(),m1[i]=a,ans+=a;while(a--) b=rd(),add(i,b+n,inf,0),m2[b]++;}for(i=1;i<=n;i++) add(S,i,inf,m1[i]),add(i+n,T,inf,m2[i]),add(i+n,i,inf,0);swap(S,T);while(bfs()) ans-=dfs(S,inf);printf("%d",ans);return 0; }

轉載于:https://www.cnblogs.com/CQzhangyu/p/7297651.html

總結

以上是生活随笔為你收集整理的【BZOJ2625】[Neerc2009]Inspection 最小流的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 中文字幕8 | 色一情一伦一子一伦一区 | 99热精品在线观看 | 黄色免费播放 | 少妇人禽zoz0伦视频 | 日韩一区免费 | 亚洲熟女综合色一区二区三区 | 午夜国产一区二区三区 | 91看片免费| 成人av免费在线观看 | 日韩乱码人妻无码中文字幕久久 | 久操热久操 | 1000部啪啪未满十八勿入 | 羞羞的视频网站 | 久久成人乱码欧美精品一区二区 | 国产乱淫片视频 | 午夜精品久久久久久久无码 | 欧美综合亚洲图片综合区 | 亚洲综合精品一区 | 国产真实乱人偷精品视频 | 日日夜夜爽爽 | 97人妻精品一区二区三区软件 | 国产精品久久久一区二区三区 | 亚洲成av人片| 色天天| 欧美日韩有码 | 午夜8888| 一区二区片 | 国产激情在线 | 美女喷液视频 | 激情文学亚洲色图 | 天天爱天天操 | 欧美性猛交久久久乱大交小说 | 欧美日韩免费在线视频 | av字幕网| 欧美日比视频 | 国产原创一区 | 四虎永久在线精品免费网址 | 日本视频免费在线播放 | 日韩污污 | 亚洲国产精品激情在线观看 | 夜夜嗨aⅴ一区二区三区 | 天堂影院一区二区 | 国产精品亚洲视频 | 亚洲精品国产视频 | 国产吞精囗交免费视频网站 | 五月天激情社区 | 欧美激情在线一区二区 | 色播综合| jlzzzjlzzz国产免费观看 | 少妇特殊按摩高潮惨叫无码 | 在线亚洲观看 | 91高跟黑色丝袜呻吟动态图 | 男女偷爱性视频刺激 | 成人做爰9片免费视频 | 日韩色图视频 | 亚洲丝袜一区 | 91香蕉视频在线看 | 成人在线免费 | 欧美一级免费大片 | 艳母免费在线观看 | 日本一区二区三区久久久久 | 亚洲国产精品99 | 日韩免费视频网站 | 自由 日本语 热 亚洲人 | 五月婷婷丁香六月 | 奇米精品一区二区三区四区 | 亚洲一级网 | 国产在线超碰 | 俺来也在线视频 | 久久国产免费视频 | 黑人导航 | 亚洲欧美视频二区 | 纯爱无遮挡h肉动漫在线播放 | 91国偷自产中文字幕久久 | 黄色综合| 成人毛片18女人毛片 | 6080午夜| 少妇人妻一级a毛片 | 天天干,天天干 | 日韩性猛交ⅹxxx乱大交 | 又黄又爽视频 | 在线视频网 | 日韩片在线观看 | 红色假期黑色婚礼2 | 8x国产一区二区三区精品推荐 | 国产欧美日韩三级 | 国产毛片久久久久久国产毛片 | 男欢女爱久石 | 夜夜躁狠狠躁 | 中文字幕亚洲无线码在线一区 | 成人在线观看你懂的 | 美女极度色诱图片www视频 | 免费在线观看一区二区三区 | 久久久久久av无码免费网站下载 | 已婚少妇美妙人妻系列 | 四川丰满妇女毛片四川话 | 日韩区欧美区 | 无码毛片aaa在线 |