博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 1187 G - Gang Up
阅读量:5337 次
发布时间:2019-06-15

本文共 2564 字,大约阅读时间需要 8 分钟。

思路:

每个点按时间拆点建边,然后跑最小费用流

一次走的人不能太多,假设每次走的人为k

(k*k-(k-1)*(k-1))*d <= c+d

k <= 24

代码:

#pragma GCC optimize(2)#pragma GCC optimize(3)#pragma GCC optimize(4)#include
using namespace std;#define y1 y11#define fi first#define se second#define pi acos(-1.0)#define LL long long//#define mp make_pair#define pb push_back#define ls rt<<1, l, m#define rs rt<<1|1, m+1, r#define ULL unsigned LL#define pll pair
#define pli pair
#define pii pair
#define piii pair
#define pdd pair
#define mem(a, b) memset(a, b, sizeof(a))#define debug(x) cerr << #x << " = " << x << "\n";#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);//head int n, m, k, c, d, a[55], x, y;const int N = 5000 + 10;const int INF = 0x3f3f3f3f;struct edge { int to, cap, cost, rev;};int V;vector
g[N];int h[N], dis[N], prevv[N], preve[N];void add_edge(int u, int v, int cap, int cost) { g[u].pb({v, cap, cost, g[v].size()}); g[v].pb({u, 0, -cost, g[u].size()-1});}int min_cost_flow(int s, int t, int f) { int res = 0; mem(h, 0); while(f > 0) { priority_queue
, greater
> q; mem(dis, 0x3f); dis[s] = 0; q.push({ 0, s}); while(!q.empty()) { pii p = q.top(); q.pop(); int v = p.se; if(dis[v] < p.fi) continue; for (int i = 0; i < g[v].size(); ++i) { edge &e = g[v][i]; if(e.cap > 0 && dis[e.to] > dis[v] + e.cost + h[v] - h[e.to]) { dis[e.to] = dis[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v; preve[e.to] = i; q.push({dis[e.to], e.to}); } } } if(dis[t] == INF) return -1; for (int v = 0; v < V; ++v) h[v] += dis[v]; int d = f; for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap); f -= d; res += d*h[t]; for (int v = t; v != s; v = prevv[v]) { edge &e = g[prevv[v]][preve[v]]; e.cap -= d; g[v][e.rev].cap += d; } } return res;}int s, t;int main() { scanf("%d %d %d %d %d", &n, &m, &k, &c, &d); for (int i = 1; i <= k; ++i) scanf("%d", &a[i]); s = 0, t = 100*n+1; for (int i = 1; i <= k; ++i) add_edge(s, (a[i]-1)*100+1, 1, 0); for (int i = 1; i <= 100; ++i) add_edge(i, t, k, 0); for (int i = 1; i <= n; ++i) { for (int j = 1; j < 100; ++j) add_edge((i-1)*100+j, (i-1)*100+j+1, k, c); } for (int i = 1; i <= m; ++i) { scanf("%d %d", &x, &y); for (int j = 1; j < 100; ++j) { for (int k = 1; k <= 24; ++k) { add_edge((x-1)*100+j, (y-1)*100+j+1, 1, (k*k-(k-1)*(k-1))*d+c); add_edge((y-1)*100+j, (x-1)*100+j+1, 1, (k*k-(k-1)*(k-1))*d+c); } } } V = 100*n+2; printf("%d\n", min_cost_flow(s, t, k)); return 0;}

 

转载于:https://www.cnblogs.com/widsom/p/11129077.html

你可能感兴趣的文章
BZOJ 1090 [SCOI2003]字符串折叠
查看>>
Error: [WinError 10013] 以一种访问权限不允许的方式做了一个访问套接字的尝试。...
查看>>
python对mysql进行简单操作
查看>>
题解:[APIO/CTSC 2007]数据备份
查看>>
HttpClient怎么上传文件
查看>>
linux下open-vswitch安装卸载操作
查看>>
jquery hover 代替mouseover,mouseout事件
查看>>
SpringMVC 拦截器简单配置
查看>>
第一次作业小结
查看>>
erlang http post 发送数据请求
查看>>
Unresolved external CheckAutoResult
查看>>
[收藏转贴]struct探索·extern "C"含义探索 ·C++与C的混合编程·C 语言高效编程的几招...
查看>>
tinkcmf视频上传大小限制
查看>>
解决“并非来自 Chrome 网上应用店。”
查看>>
《第1章:统计学习方法概论》
查看>>
JS定时器时间日期钟表
查看>>
partial(C# 参考)
查看>>
Supervisor介绍、安装及配置
查看>>
openshift 添加cron定时任务
查看>>
sublime text3在指定浏览器上本地服务器(localhost)运行文件(php)
查看>>