嘟嘟嘟




这其实就是一个最小流的板子题。把每一条边的流量至少为1,然后建立附加源汇跑一遍最大流,连上\(t, s\),再跑一遍最大流就是答案。




刚开始我想错了:统计每一个点的出度和入度,去两者较大值\(w\),则流经这个点的流量至少为\(w\)。所以我就拆点,从\(i\)向\(i'\)连一条容量为\([w, INF]\)的边,其他边没有容量限制。

但其实这种建图方式是错的,因为可以有一条边流了很多,满足了他出去的点的流量限制,从而导致有一些边没有走,使答案变小。

举个例子,

比如原图是这样的:



答案应该是3.

按我的想法,建出来的图是这样的:



每一条边都符合了流量下限,但是却有两条边没流到,得到的结果是2。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 105;
const int maxe = 1e6 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n, s, t, S, T;
int du[maxn];
struct Edge
{
int nxt, to, cap, flow;
}e[maxe];
int head[maxn << 1], ecnt = -1;
In void addEdge(int x, int y, int w)
{
e[++ecnt] = (Edge){head[x], y, w, 0};
head[x] = ecnt;
e[++ecnt] = (Edge){head[y], x, 0, 0};
head[y] = ecnt;
} int dis[maxn << 1];
In bool bfs(int s, int t)
{
Mem(dis, 0); dis[s] = 1;
queue<int> q; q.push(s);
while(!q.empty())
{
int now = q.front(); q.pop();
for(int i = head[now], v; ~i; i = e[i].nxt)
{
if(!dis[v = e[i].to] && e[i].cap > e[i].flow)
dis[v] = dis[now] + 1, q.push(v);
}
}
return dis[t];
}
int cur[maxn << 1];
In int dfs(int now, int res, int t)
{
if(now == t || res == 0) return res;
int flow = 0, f;
for(int& i = cur[now], v; ~i; i = e[i].nxt)
{
if(dis[v = e[i].to] == dis[now] + 1 && (f = dfs(v, min(res, e[i].cap - e[i].flow), t)) > 0)
{
e[i].flow += f; e[i ^ 1].flow -= f;
flow += f; res -= f;
if(res == 0) break;
}
}
return flow;
} In int maxflow(int s, int t)
{
int flow = 0;
while(bfs(s, t))
{
memcpy(cur, head, sizeof(head));
flow += dfs(s, INF, t);
}
return flow;
} int main()
{
Mem(head, -1);
n = read(); s = 0, t = n + n + 1;
S = t + 1, T = t + 2;
for(int i = 1; i <= n; ++i)
{
addEdge(s, i, INF), addEdge(i, t, INF);
int k = read(); du[i] += k;
for(int j = 1; j <= k; ++j)
{
int v = read(); --du[v];
addEdge(i, v, INF - 1);
}
}
for(int i = 1; i <= n; ++i)
if(du[i] >= 0) addEdge(i, T, du[i]);
else addEdge(S, i, -du[i]);
maxflow(S, T);
addEdge(t, s, INF);
write(maxflow(S, T)), enter;
return 0;
}

luogu P4843 清理雪道的更多相关文章

  1. BZOJ 2502 Luogu P4843 清理雪道 最小流

    题意: 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定时清理雪道.你们拥有一架直升飞机 ...

  2. BZOJ 2502 清理雪道/ Luogu P4843 清理雪道 (有源汇上下界最小流)

    题意 有一个有向无环图,求最少的路径条数覆盖所有的边 分析 有源汇上下界最小流板题,直接放代码了,不会的看dalao博客:liu_runda 有点长,讲的很好,静心看一定能看懂 CODE #inclu ...

  3. P4843 清理雪道

    题目地址:P4843 清理雪道 上下界网络流 无源汇上下界可行流 给定 \(n\) 个点, \(m\) 条边的网络,求一个可行解,使得边 \((u,v)\) 的流量介于 \([B(u,v),C(u,v ...

  4. P4843 清理雪道(上下界网络流)

    P4843 清理雪道 上下界最小流 我们先搞一遍上下界可行流(转) 回忆上下界最大流的写法:在可行流的残量网络$s\ -\ t$上跑最大流,答案为可行流$+$残量网络的最大流 那么上下界最小流的写法呢 ...

  5. 洛谷P4843 清理雪道

    题意:给你DAG,求最小路径边覆盖.路径可重. 解:首先可以想到边转点,发现有n²条边,果断超时. 有源汇有上下界最小流. 建图:每条边都建立一条边,流量限制为[1, 1]. 源点向每个点连边,因为都 ...

  6. 【BZOJ-2502】清理雪道 有上下界的网络流(有下界的最小流)

    2502: 清理雪道 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 594  Solved: 318[Submit][Status][Discuss] ...

  7. [BZOJ2502]清理雪道

    [BZOJ2502]清理雪道 试题描述 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降的方向. 你的团队负责每周定 ...

  8. BZOJ 2502: 清理雪道 [最小流]

    2502: 清理雪道 题意:任意点出发任意次每条边至少经过一次最小花费. 下界1,裸最小流.... #include <iostream> #include <cstdio> ...

  9. BZOJ_2502_清理雪道_有源汇上下界最小流

    BZOJ_2502_清理雪道_有源汇上下界最小流 Description        滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道), ...

随机推荐

  1. 优化方法总结以及Adam存在的问题(SGD, Momentum, AdaDelta, Adam, AdamW,LazyAdam)

    优化方法总结以及Adam存在的问题(SGD, Momentum, AdaDelta, Adam, AdamW,LazyAdam) 2019年05月29日 01:07:50 糖葫芦君 阅读数 455更多 ...

  2. 解决go mod或go get时`x509: certificate signed by unknown authority`错误

    一般go get私有仓库时会出现如下错误: go: xxx@v0.0.0-20190918102752-bb51b27911ca: unrecognized import path "xxx ...

  3. [转载]为什么jar包中能看见源码

    [转载]为什么jar包中能看见源码 这个也是我之前发现过的一个现象,只是之前没有研究过.今天正好在知乎看见,总结一下: 对于Maven或者Gradle项目,依赖的部分会自动从远程仓库下载源码 生成的j ...

  4. php--最新正则(手机号码)

    这次给大家带来正则验证(2018最新最全手机号验证),正则验证(2018最新最全手机号验证)的注意事项有哪些,下面就是实战案例,一起来看一下. 下面给大家分享2018手机号正则表达式验证方法,具体内容 ...

  5. echarts 内存泄漏

    最近使用vue + Echarts 实现vue项目的数据可视化功能的时候,在ios环境下,点击列表页进入详情页几次就白屏了. 感觉白屏的原因是:echarts频繁初始化画图时候有内存泄漏,吃掉了所有内 ...

  6. netstat用法详解

    netstat用法详解 知识,netstat用法详解 图片 netstat用法详解 内容,netstat用法详介绍,netstat用法详正文 netstat命令是一个监控TCP/IP网络的非常有用的工 ...

  7. bootstrap 处理警告

    $("#id").bootstrapValidator({}).on('success.field.bv', function (e, data) { })

  8. 忘记root密码,修改方法

    Linux的root密码修改不像Windows的密码修改找回,Windows的登录密码忘记需要介入工具进行解决.CentOS6和CentOS7的密码方法也是不一样的,具体如下: 首先是CentOS 6 ...

  9. css div嵌套层中button的margin-top不起作用解决方法

    首先声明本人资质尚浅,本文只用于个人总结.如有错误,欢迎指正.共同提高. --------------------------------------------------------------- ...

  10. 浅谈String、StringBuffer与StringBuilder

    浅谈String.StringBuffer与StringBuilder   先详细介绍一下String.StringBuffer与StringBuilder String: 官方对String的说明: ...