設定源點和匯點,每個需要使用的裝置插座,連線源點到該插座的裝置個數,連線會場提供插座到匯點,容量為個數,然後連線插座轉換邊,容量為無窮
注意轉換插座可能是之前沒出現過的
#include #include #include #include #include #include #include #include #include #include using namespace std;
typedef long long ll;
const double pi = acos(-1.0);
template inline t max(t a, t b)
template inline t min(t a, t b)
const int n = 444;
const int m = 1111;
const ll mod = 1000000007ll;
const int dir[4][2] = ;
const int inf = 0x3f3f3f3f;
struct arclist e[n + m << 1];
int head[n], cur;
inline void init()
inline void add(int u, int v, int cap = 1)
int sap(int s, int t, int n)
, gap[n] = {};
int cur[n]; memcpy(cur, head, sizeof(cur));
gap[0] = n + 1; ++gap[dis[s] = 1];
for (int u = pre[s] = s; dis[s] <= n; ++gap[++dis[u]], u = pre[u])
for (int i = s; i != t; i = e[cur[i]].v)
maxflow += aug;
}break;}}
if (--gap[dis[u]] == 0) break;
dis[u] = n;
for (int p = head[u]; ~p; p = e[p].next)
if (e[p].cap && dis[u] > dis[e[p].v])
}return maxflow;
}}flow;
int to[n], from[n], ct[n], ct1[n];
int trans[n], trant[n];
int main()
ct1[temp]++;
}scanf("%d", &n);
num = n;
for (i = 0; i < n; ++i)
ct[temp]++;
}scanf("%d", &n);
for (i = 0; i < n; ++i)
if (index[s]) tp2 = index[s];
else
trans[cnt3] = tp1; trant[cnt3++] = tp2;
}for (i = 0; i < tot; ++i)
for (i = 0; i < tot; ++i)
for (i = 0; i < cnt3; ++i)
flow.add(trans[i], trant[i], inf);
printf("%d\n", num - flow.sap(0, tot, tot + 1));
return 0;
}
POJ 1087 最大流 EK演算法
include include include include include include include includeusing namespace std const int maxn 1003 const int inf 0x3f3f3f3f int n,m int s,t int m1...
poj1087解題報告(最大流 EK演算法)
題目大意 題意 有n個不同的插座,有m臺不同的機器需要m種插頭,有k組轉換 插頭a能由插頭b轉換而來。問這些機器最少有幾台不能插上插座。解題思路 使用網路流,以裝置的插頭型別和插座的插頭型別組成乙個圖,建立超級源點,超級匯點,源點到裝置的流量為1,插座到匯點的流量為1,裝置和流量之間流量為無限大 可...
poj3281網路流之最大流
加乙個源點和匯點,把每頭牛拆成兩個點,不拆點的話可能會出現多對食物與飲料被乙個牛享用的情況,拆點後流量為1,不能同時通過了 然後用最大流處理,每個鏈結邊都是1 include include include include include include include include includ...