HDU 6214 Smallest Minimum Cut 邊最少的最小割

0

Smallest Minimum Cut

2017 icpc 青島網(wǎng)絡(luò)賽
這東西其實(shí)是個(gè)原題
Harry Potter and the Forbidden Forest
百度了一下 hdu3987 的做法大概有兩種

1

先跑一遍最大流, 再在殘量網(wǎng)絡(luò)上, 把滿流的路徑流量設(shè)為 1, 其余均設(shè)為 INF, 再跑一遍最大流

2

一開始加邊的時(shí)候, 把所有的邊流量設(shè)為 原流量 乘以 一個(gè)大于總邊數(shù)的值 加 1, 再跑一遍最大流, 最大流的結(jié)果 模 一開始乘的大于總邊數(shù)的數(shù)字

很悲催的選擇了第一種做法, 然后 WA 到死, 群巨說(shuō)這個(gè)做法是錯(cuò)誤的= =

1

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

const int INF = 1e9;
const int MAXN = 200;
const int MAXM = 1000;
const int minE = (MAXM << 1) + 7;

struct Edge{
    int to, cap, next;
};

Edge Edges[MAXM << 1 | 1];
int head[MAXN + 1], cnt;

int d[MAXN + 1], q[MAXN + 1];

void MaxFlowInit(){
    cnt = 0;
    memset(head, -1, sizeof(head));
}

bool MaxFlowBfs(int s, int t){
    int rear = 0;
    memset(d, -1, sizeof(d));
    d[s] = 0, q[rear++] = s;
    for(int i = 0; i < rear; i++){
        for(int j = head[q[i]]; ~j; j = Edges[j].next){
            Edge& e = Edges[j];
            if(e.cap && d[e.to] == -1){
                d[e.to] = d[q[i]] + 1;
                q[rear++] = e.to;
                if(e.to == t) return 1;
            }
        }
    }
    return 0;
}

int MaxFlowDfs(int s, int t, int cur,int maxflow){
    if(cur == t) return maxflow;
    for(int i = head[cur]; ~i; i = Edges[i].next){
        Edge& e = Edges[i];
        if(e.cap && d[e.to] == d[cur] + 1)
            if(int det = MaxFlowDfs(s, t, e.to, min(maxflow, e.cap))){
                e.cap -= det, Edges[i ^ 1].cap += det;
                return det;
            }
    }
    return 0;
}

int MaxFlowDinic(int s, int t){
    int flow = 0;
    while(MaxFlowBfs(s, t)) flow += MaxFlowDfs(s, t, s, INF);
    return flow;
}

void AddEdge(int u, int v, int c){
    Edges[cnt].to = v, Edges[cnt].cap = c, Edges[cnt].next = head[u], head[u] = cnt++;
    Edges[cnt].to = u, Edges[cnt].cap = 0, Edges[cnt].next = head[v], head[v] = cnt++;
}

int main()
{
    int T, n, m, s, t;

    scanf("%d", &T);
    for(int cas = 1; cas <= T; cas++){
        MaxFlowInit();
        scanf("%d%d%d%d", &n, &m, &s, &t);
        for(int i = 0, u, v, w; i < m; i++){
            scanf("%d%d%d", &u, &v, &w);
            AddEdge(u, v, w * minE + 1);
        }
        printf("%d\n", MaxFlowDinic(s, t) % minE);
    }
    return 0;
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 聽音樂(lè)卻對(duì)音樂(lè)種類有些模糊閑暇之余不妨簡(jiǎn)單了解目前主要音樂(lè)種類 定義 這種音樂(lè)模式完全以純粹優(yōu)美的音樂(lè)來(lái)敘述表達(dá)作...
    三羊洋閱讀 5,973評(píng)論 3 5
  • 《某午后》 大概是這樣消磨時(shí)間的方式 紅的建筑立于半小時(shí)以后的 公交車碎片中 我們計(jì)算腳步觸摸的寬度 然后 朝虛空...
    EliotLolita閱讀 219評(píng)論 0 0
  • 初創(chuàng)公司是我的第四次實(shí)習(xí)選擇,坦白說(shuō)這條路是比較難的,但是最難得的不是工作或者指標(biāo),而是這是一天看不見的未知路,成...
    小覷閱讀 292評(píng)論 0 0

友情鏈接更多精彩內(nèi)容