BZOJ3511: 土地劃分

【傳送門:BZOJ3511】


簡要題意:

  給出n個點,m條邊,每個點有A和B兩種形態,一開始1為A,n為B

  給出VA[i]和VB[i],表示第i個點選擇A和B形態的價值

  每條邊給出x,y,EA,EB,EC,表示如果x和y都為A,則獲得EA價值,如果都為B則獲得EB價值,否則會得到EC的費用(就是負價值)

  求出最大價值


題解:

  神奇的最小割,太強了

  建圖膜


參考代碼:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{int x,y,c,next,other;
}a[2100000];int len,last[110000];
void ins(int x,int y,int c)
{int k1=++len,k2=++len;a[k1].x=x;a[k1].y=y;a[k1].c=c;a[k1].next=last[x];last[x]=k1;a[k2].x=y;a[k2].y=x;a[k2].c=0;a[k2].next=last[y];last[y]=k2;a[k1].other=k2;a[k2].other=k1;
}
int h[110000],list[110000],st,ed;
bool bt_h()
{memset(h,0,sizeof(h));h[st]=1;int head=1,tail=2;list[1]=st;while(head!=tail){int x=list[head];for(int k=last[x];k;k=a[k].next){int y=a[k].y;if(h[y]==0&&a[k].c>0){h[y]=h[x]+1;list[tail++]=y;}}head++;}if(h[ed]==0) return false;else return true;
}
int findflow(int x,int f)
{if(x==ed) return f;int s=0,t;for(int k=last[x];k;k=a[k].next){int y=a[k].y;if(h[y]==(h[x]+1)&&a[k].c>0&&f>s){t=findflow(y,min(a[k].c,f-s));s+=t;a[k].c-=t;a[a[k].other].c+=t;}}if(s==0) h[x]=0;return s;
}
int main()
{int n,m;scanf("%d%d",&n,&m);int sum=0;st=0;ed=n+2*m+1;len=0;memset(last,0,sizeof(last));ins(st,1,999999999);for(int i=2;i<n;i++){int d;scanf("%d",&d);sum+=d;ins(st,i,d);}ins(n,ed,999999999);for(int i=2;i<n;i++){int d;scanf("%d",&d);sum+=d;ins(i,ed,d);}for(int i=1;i<=m;i++){int x,y,ea,eb,ec;scanf("%d%d%d%d%d",&x,&y,&ea,&eb,&ec);sum+=ea+eb;ins(x,y,ec);ins(y,x,ec);ins(i+n,x,999999999);ins(i+n,y,999999999);ins(x,i+n+m,999999999);ins(y,i+n+m,999999999);ins(st,i+n,ea);ins(i+n+m,ed,eb);}while(bt_h()==true) sum-=findflow(st,999999999);printf("%d\n",sum);return 0;
}

?

轉載于:https://www.cnblogs.com/Never-mind/p/8636914.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/280854.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/280854.shtml
英文地址,請注明出處:http://en.pswp.cn/news/280854.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

facebook 文本分類_如何禁用和自定義Facebook的通知,文本和電子郵件

facebook 文本分類Facebook is really keen on keeping you on their platform. One of the ways they do that is by sending you notifications whenever the tiniest thing happens. And you won’t just see them on the site—Facebook will also notify you by email, wi…

django06: ORM示例2--uer 與file

存放路徑&#xff1a;https://git.lug.ustc.edu.cn/ 筆記 外鍵與多鍵 path models.ForeignKey(to"Path")file models.ManyToManyField(to"File") code 處理方式 new_path request.POST.get("new_path",None)models.File.objects.create(…

Error opening terminal: xterm-256color

在使用gdb調試linux內核時&#xff0c;提示如下錯誤&#xff1a; arm-none-linux-gnueabi-gdb --tui vmlinux Error opening terminal: xterm-256color. 解決辦法&#xff1a; 1、 edit your .bash_profile file vim .bash_profile 2、commnet #export TERMxterm-256colo…

四種簡單的排序算法

四種簡單的排序算法 我覺得如果想成為一名優秀的開發者&#xff0c;不僅要積極學習時下流行的新技術&#xff0c;比如WCF、Asp.Net MVC、AJAX等&#xff0c;熟練應用一些已經比較成熟的技術&#xff0c;比如Asp.Net、WinForm。還應該有著牢固的計算機基礎知識&#xff0c;比如數…

Xampp修改默認端口號

為什么80%的碼農都做不了架構師&#xff1f;>>> Xampp默認的端口使用如下&#xff1a; Httpd使用80端口 Httpd_ssl使用443端口 Mysql使用3306端口 ftp使用21端口 但是&#xff0c;在如上端口被占用的情況下&#xff0c;我們可以通過修改xampp默認端口的方法&…

為什么csrss進程有三個_什么是客戶端服務器運行時進程(csrss.exe),為什么在我的PC上運行它?...

為什么csrss進程有三個If you have a Windows PC, open your Task Manager and you’ll definitely see one or more Client Server Runtime Process (csrss.exe) processes running on your PC. This process is an essential part of Windows. 如果您使用的是Windows PC&…

使用c#的 async/await編寫 長時間運行的基于代碼的工作流的 持久任務框架

持久任務框架 &#xff08;DTF&#xff09; 是基于async/await 工作流執行框架。工作流的解決方案很多&#xff0c;包括Windows Workflow Foundation&#xff0c;BizTalk&#xff0c;Logic Apps, Workflow-Core 和 Elsa-Core。最近我在Dapr 的倉庫里跟蹤工作流構建塊的進展時&a…

bat批處理筆記

變量 1.CMD窗口變量&#xff0c;變量名必須用單%引用&#xff08;即&#xff1a;%variable&#xff09; 外部變量&#xff0c;是系統制定的&#xff0c;只有9個&#xff0c;專門保存外部參數的&#xff0c;就是運行批處理時加的參數。只有 %1 %2 %3 %4 ...... %9。 在bat內直…

多目標跟蹤(MOT)論文隨筆-SIMPLE ONLINE AND REALTIME TRACKING (SORT)

轉載請標明鏈接&#xff1a;http://www.cnblogs.com/yanwei-li/p/8643336.html 網上已有很多關于MOT的文章&#xff0c;此系列僅為個人閱讀隨筆&#xff0c;便于初學者的共同成長。若希望詳細了解&#xff0c;建議閱讀原文。 本文是使用 tracking by detection 方法進行多目標…

明日大盤走勢分析

如上周所述&#xff0c;大盤在4與9號雙線壓力下&#xff0c;上攻乏力。今天小幅下跌0.11%&#xff0c;漲511&#xff0c;平76&#xff0c;跌362&#xff0c;說明個股還是比較活躍&#xff0c;而且大盤上漲趨勢未加改變&#xff0c;只是目前攻堅&#xff0c;有點缺乏外部的助力。…

android EventBus 3.0 混淆配置

2019獨角獸企業重金招聘Python工程師標準>>> https://github.com/greenrobot/EventBus 使用的這個庫在github的官網README中沒有寫明相應混淆的配置. 經過對官網的查詢&#xff0c;在一個小角落還是被我找到了。 -keepattributes *Annotation* -keepclassmembers …

dotnet-exec 0.11.0 released

dotnet-exec 0.11.0 releasedIntrodotnet-exec 是一個 C# 程序的小工具&#xff0c;可以用來運行一些簡單的 C# 程序而無需創建項目文件&#xff0c;讓 C# 像 python/nodejs 一樣簡單&#xff0c;而且可以自定義項目的入口方法&#xff0c;支持但不限于 Main 方法。Install/Upd…

C# 讀取文件內容/輸出txt log

逐行讀 jsonString string.Empty;if (File.Exists(jsonFile)){StreamReader sr new StreamReader(jsonFile, Encoding.UTF8);string line string.Empty;while ((line sr.ReadLine()) ! null){jsonString line;}sr.Close();} 全讀取 string text File.ReadAllText("…

樹形dp-CF-337D. Book of Evil

題目鏈接&#xff1a; http://codeforces.com/problemset/problem/337/D 題目大意&#xff1a; 給一棵樹&#xff0c;m個點&#xff0c;一個距離d&#xff0c;求有多少個點A,使得A到所有的m個點距離都不超過d. 解題思路&#xff1a; 樹形dp. 有兩種方法可以解&#xff1a; 1、類…

運行時獲取類庫信息

運行時獲取類庫信息Intro在我們向別的開源項目提 issue 的時候&#xff0c;可能經常會遇到別人會讓我們提供使用的版本信息&#xff0c;如果別的開源項目類庫集成了 source link&#xff0c;我們可以從程序集信息中獲取到版本以及對應的 commit 信息&#xff0c;這樣我們就可以…

Oracle數據表中輸入引號等特殊字符

Oracle輸入特殊字符的特殊方法: UPDATE BOOKMARK SET BM_VALUEq/ --在這里寫下需要輸入的內容&#xff08;可以包括引號、回車等特殊的符號&#xff09;,所見即所得 / -- WHERE BM_NAMEXX

xbox360鏈接pc_如何將實時電視從Xbox One流式傳輸到Windows PC,iPhone或Android Phone

xbox360鏈接pcSet up your Xbox One’s TV integration and you can do more than just watch TV on your Xbox: you can also stream that live TV from your Xbox to a Windows 10 PC, Windows phone, iPhone, iPad, or Android device over your home network. 設置Xbox One…

PS2019工具介紹筆記(一)

通用快捷鍵 ALT鼠標滾輪放大縮小 空格按左鍵 移動圖片 一、新建 PPI 顯示器72PPI 印刷(國際通用分辨率)300PPI 海報高清寫真96-200PPI 大型噴繪25-50PPI 顏色模式 RGB(紅綠藍) CMYK(青洋紅黃黑)印刷業 二、移動工具 ctrlT 圖形自由變換 alt…

WPF ABP框架更新日志(最新2022-11月份)

更新說明本次更新內容包含了WPF客戶端以及Xamarin.Forms移動端項目, 更新內容總結如下:WPF 客戶端修復啟動屏幕無法跳轉異常修復添加好友異常修復托盤圖標狀態更新異常優化好友發送消息時狀態檢測更新聊天窗口UI風格更新好友列表得頭像顯示更新聊天窗口消息日期分組顯示更新系統…

JSONObject和JSONArray 以及Mybatis傳入Map類型參數

import org.json.JSONArray;import org.json.JSONObject;將字符串轉化為JSONArray JSONArray jsonArray new JSONArray(deviceInfo); //注意字符串的格式將JSONArray轉化為JSONObject類型 JSONObject jsonObject jsonArray.getJSONObject(0);將值存入Map Map<String,S…