bzoj 2597 剪刀石頭布(費用流)

2021-08-15 02:47:12 字數 2293 閱讀 1621

傳送門biu~

一張競賽圖中,任意選三個點如果不形成環,那麼一定有乙個點的出度為2。也就是每當在任意乙個點中找到任意兩個出度,圖中就會失去乙個三元環。 令點i

i

的出度為de

gree

i' role="presentation" style="position: relative;">deg

reei

degr

eei,則對於整張圖來說,三元環的個數為c3

n−σc

2deg

reei

c n3

−σcd

egre

ei

2。問題就變成了在邊數恆定時如何使σc

2deg

reei

σ cd

egre

ei

2最小。可以看出,每當乙個點

i i

的degree

i' role="presentation" style="position: relative;">deg

reei

degr

eei加一,就會減少de

gree

i−1 deg

reei

−1

個三元環。所以可以把每條邊用乙個點來表示,以出度為流量,構建最小費用最大流模型:

① ①

源點s' role="presentation" style="position: relative;">s

s向每個原圖中的節點連n−

1 n−1

條弧,流量均為

1 1

。費用分別為0、

1、2....n−

2' role="presentation" style="position: relative;">0、1

、2....n−

20、1

、2....n−

2,代表著每次這個節點連出一條出邊(即de

gree

i deg

reei

++)時所減少的三元環數量。

② ②

每個原圖中的節點向自己的出邊連一條流量為

1' role="presentation" style="position: relative;">1

1,費用為

0 0

的弧。

③' role="presentation" style="position: relative;">③

③每條邊向匯點

t t

連一條流量為

1' role="presentation" style="position: relative;">1

1,費用為

0 0

的弧。

求最小費用,再用cn

3' role="presentation" style="position: relative;">c3n

cn3減去即為所求的最多三元環的數量。求方案時只需要判斷原圖中邊的輔助點是在哪個方向被流過的即可。

#include

using

namespace

std;

const

int inf=1e9;

int n,s,t,cost,a[105][105],edge[105][105],dis[10105];

int head[10105],fir[10105],nex[60005],to[60005],cap[60005],val[60005],tp=1;

bool b[10105];

inline

int calc(int x,int y)

inline

void add(int x,int y,int c,int v)

inline

void insert(int x,int y,int c,int v)

inline

bool spfa()}}

return dis[t]^inf;

}int dfs(int x,int now)

int c=0;b[x]=true;

for(int &i=fir[x];i;i=nex[i])

}return c;

}inline

void dinic()

}int main()

}dinic();

printf("%d\n",n*(n-1)*(n-2)/6-cost);

for(int i=1;i<=n;++i)

}return

0;}

bzoj 2597 石頭剪刀布

利用補集轉化建圖。可以得到ans c n,3 sigma c win i 2 具體的意思就是兩個勝場會破壞乙個三元環。之後展開,注意sigma win i n n 1 2,因為比賽場次是c n,2 個,因為寫成了n,一直wa include include include include inclu...

WC2007 bzoj2597 剪刀石頭布

description 在一些一對一遊戲的比賽 如下棋 桌球和羽毛球的單打 中,我們經常會遇到a勝過b,b勝過c而c又勝過a的有趣情況,不妨形象的稱之為剪刀石頭布情況。有的時候,無聊的人們會津津樂道於統計有多少這樣的剪刀石頭布情況發生,即有多少對無序三元組 a,b,c 滿足其中的乙個人在比賽中贏了另...

bzoj2597 Wc2007 剪刀石頭布

今天注意力明顯不集中哎 頹 1a 了這道網路流題,思路確實神。題目是給你一張有向圖,讓你新增一些邊使得任意兩個點 a,b 直接都有一條有向邊,可以從a指向b,也可以由b指向a。讓你最大化三元環的數目。according to 姜爺,用補集思想,環不好搞,考慮三個點不成環,那那就是有乙個點連向其它的兩...