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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

codecomb 2091【路径数量】

發布時間:2025/3/13 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codecomb 2091【路径数量】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

好久沒有更新博客了啊……屯了一堆題沒發呢

這是喪心病狂的hzwer每日NOI模擬賽第一天的第一題

媽蛋說好的NOIP難度圖論算法兩題網絡流!讓我說什么好

唔……codecomb的頁面在晚上就會變得很奇怪

?

題目描述

???????????給定一張n個點的有向圖,求從點1到點n最多有多少條不相交的簡單路徑。所謂不相交即不經過相同的邊的路徑。

輸入格式

第一行讀入一個n,m,表示共n個點,m條邊。

接下來m行,每行兩個整數x,y,表示從x到y有一條有向邊。

輸出格式

輸出僅包括一行,即最多有多少條不相交的簡單路勁。

樣例數據 1

輸入  [復制]

?

4 7?
1 2?
1 2?
2 3?
2 3?
2 3?
3 4?
3 4

輸出

2

備注

對于20%的數據n<=10,m<=1000;

對于100%的數據n<=1000,m<=100000;

一看就是sb無腦網絡流了……十分鐘打完還算快

#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<deque> #include<set> #include<map> #include<ctime> #define LL long long #define inf 0x7ffffff #define pa pair<int,int> #define pi 3.1415926535897932384626433832795028841971 #define S 1 #define T n using namespace std; struct edge{int to,next,v; }e[200010]; int head[10010]; int n,m,cnt=1,t,w,ans; int h[10010]; int q[100010]; inline void ins(int u,int v,int w) {e[++cnt].to=v;e[cnt].v=w;e[cnt].next=head[u];head[u]=cnt; } inline void insert(int u,int v,int w) {ins(u,v,w);ins(v,u,0); } inline bool bfs() {memset(h,-1,sizeof(h));t=0;w=1;h[S]=0;q[1]=S;while (t<w){int now=q[++t];for(int i=head[now];i;i=e[i].next)if (e[i].v&&h[e[i].to]==-1){h[e[i].to]=h[now]+1;q[++w]=e[i].to;}}if (h[T]==-1)return 0;return 1; } inline int dfs(int x,int f) {if (x==T||!f)return f;int used=0,w;for (int i=head[x];i;i=e[i].next)if (e[i].v&&h[e[i].to]==h[x]+1){w=used;w=dfs(e[i].to,min(e[i].v,f-w));e[i].v-=w;e[i^1].v+=w;used+=w;if (!f)return used;}if (!used)h[x]=-1;return used; } inline void dinic() {while (bfs())ans+=dfs(S,inf); } inline LL read() {LL x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f; } int main() {n=read();m=read();for (int i=1;i<=m;i++){int x=read(),y=read();insert(x,y,1);}dinic();printf("%d\n",ans); }

  

轉載于:https://www.cnblogs.com/zhber/p/4035883.html

總結

以上是生活随笔為你收集整理的codecomb 2091【路径数量】的全部內容,希望文章能夠幫你解決所遇到的問題。

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