https://vijos.org/tests/542c04dc17f3ca2064fe7718

好一场 水题 比赛啊

t1直接上暴力费用流10分QAQ,虽然一开始我觉得可以不用的,直接dfs可以得出最大流,但是写撮了就放弃了。

t2直接上暴力又是10分QAQ,虽然本来我就不会。。

t3直接上暴力还写撮了。。。。。。。。sad story

orz 小岛 orz zyf

t1:P1885  Phorni(Disillusioning)

听zyf讲完后无限仰慕。。。。最大流的确可以dfs出来orzQAQ。然后费用流就麻烦了。。

因为是树型的,显然流量是全部流向叶子的,而且叶子到根有且只有一条路径!sigh。。。这样就能保证我选了一条费用最小的路径增广一定是最优!!贪心。。。

sad。

那么我用树剖+线段树维护路径最小,至于官方题解的lct实在是仰慕orz。虽然以前听说过lct优化的网络流,但是今天第一次遇到orz。有时间去看看。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }
#define rdm(i, x) for(int i=ihead[x]; i; i=e[i].next)
#define lc x<<1
#define rc x<<1|1
#define lson l, m, lc
#define rson m+1, r, rc
#define MID (l+r)>>1 const int N=100005, oo=~0u>>1;
int n, ihead[N], cnt, d[N], id[N], fa[N], top[N], son[N], size[N], tot, num, cs[N], upd[N];
struct ED { int to, next, cap, cost; }e[N];
struct TR { int mn, tag; }t[N<<2];
struct ID { int c, id; }a[N];
void add(int u, int v, int c, int w) { e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].cap=c; e[cnt].cost=w; }
void dfs(int x, int c, int t) {
d[x]=0; int y; cs[x]=t;
rdm(i, x) {
y=e[i].to;
dfs(y, e[i].cost+c, e[i].cap);
d[x]+=min(d[y], e[i].cap);
}
if(!ihead[x]) d[x]=oo, a[++num].c=c, a[num].id=x;
}
void dfs1(int x) {
size[x]=1;
rdm(i, x) {
int y=e[i].to; fa[y]=x;
dfs1(y);
if(size[y]>size[son[x]]) son[x]=y;
size[x]+=size[y];
}
}
void dfs2(int x, int t) {
id[x]=++tot; top[x]=t; upd[tot]=cs[x]; //dbg(x); dbg(tot);
if(son[x]) dfs2(son[x], t);
rdm(i, x) if(e[i].to!=son[x]) dfs2(e[i].to, e[i].to);
}
void pushup(int x) { t[x].mn=min(t[lc].mn, t[rc].mn); }
void pushdown(int x) {
if(t[x].tag) {
int y=t[x].tag;
t[x].tag=0;
t[lc].mn+=y; t[rc].mn+=y;
t[lc].tag+=y; t[rc].tag+=y;
}
}
void build(int l, int r, int x) {
t[x].mn=oo;
if(l==r) { t[x].mn=upd[l]; return; }
int m=MID;
build(lson); build(rson);
pushup(x);
}
void update(int l, int r, int x, int L, int R, int k) {
pushdown(x);
if(L<=l && r<=R) {
t[x].tag+=k;
t[x].mn+=k;
return;
}
int m=MID;
if(L<=m) update(lson, L, R, k); if(m<R) update(rson, L, R, k);
pushup(x);
}
int query(int l, int r, int x, int L, int R) {
pushdown(x);
if(L<=l && r<=R) return t[x].mn;
int m=MID, ret=oo;
if(L<=m) ret=query(lson, L, R); if(m<R) ret=min(ret, query(rson, L, R));
return ret;
}
int getmin(int x) {
int ret=oo;// dbg(x);
while(top[x]!=1) {
ret=min(ret, query(1, n, 1, id[top[x]], id[x]));
x=fa[top[x]];
}
ret=min(ret, query(1, n, 1, 1, id[x])); //dbg(ret);
return ret;
}
void change(int x, int k) {
while(top[x]!=1) {
update(1, n, 1, id[top[x]], id[x], k);
x=fa[top[x]];
}
update(1, n, 1, 1, id[x], k);
}
bool cmp(const ID &a, const ID &b) { return a.c<b.c; } int main() {
read(n);
rep(i, n-1) {
int u=getint(), v=getint(), c=getint(), w=getint();
add(u, v, c, w);
}
dfs(1, 0, oo);
dfs1(1); dfs2(1, 1); build(1, n, 1);
sort(a+1, a+1+num, cmp);
int flow=d[1], ans=0;
//for1(i, 1, cnt)
for1(i, 1, num) {
int f=min(flow, getmin(a[i].id)); // dbg(f); dbg(a[i].id);
ans+=f*a[i].c;
change(a[i].id, -f);
flow-=f; if(flow==0) break;
}
printf("%d\n%d\n", d[1], ans);
return 0;
}

无限仰膜zyf神犇,千古神犇zyf!

Disillusioning #1 水题+原题赛(被虐瞎)的更多相关文章

  1. NOIP2018初赛普及组原题&题解

    NOIP2018初赛普及组原题&题解 目录 NOIP2018初赛普及组原题&题解 原题&答案 题解 单项选择题 第$1$题 第$2$题 第$3$题 第$4$题 第$5$题 第$ ...

  2. 2019.3.16 noiac的原题模拟赛

    RT,这太谔谔了,我不承认这是模拟赛 但是虽然是搬了三道题,题目本身也还能看,就这么着吧 (怎么机房里就我一道原题都没做过啊 T1 CF24D Broken Robot 比较简单地列出式子之后,我们发 ...

  3. [原题复现][2020i春秋抗疫赛] WEB blanklist(SQL堆叠注入、handler绕过)

    简介 今天参加i春秋新春抗疫赛 一道web没整出来 啊啊啊 好垃圾啊啊啊啊啊啊啊  晚上看群里赵师傅的buuoj平台太屌了分分钟上线 然后赵师傅还分享了思路用handler语句绕过select过滤.. ...

  4. Rectangles(第七届ACM省赛原题+最长上升子序列)

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100)  rec ...

  5. (各个公司面试原题)在线做了一套CC++综合測试题,也来測一下你的水平吧(二)

    刚才把最后的10道题又看了下.也发上来吧. 以下给出试题.和我对题目的一些理解 前10道题地址 (各个公司面试原题)在线做了一套CC++综合測试题.也来測一下你的水平吧(一) 11.设已经有A,B,C ...

  6. NOIP原题 斗地主(20190804)

    题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关 系根据牌的数码表示如下:3<4&l ...

  7. [CF676C]Vasya and String(尺取法,原题)

    题目链接:http://codeforces.com/contest/676/problem/C 原题题解链接:http://www.cnblogs.com/vincentX/p/5405468.ht ...

  8. NOIP2016原题终结测试(2017081801)

    NOIP2016还有几道原题没有写掉,今天就一并布置掉. 答案的问题,有部分会先放到NOIP题解中,是单独发布的. 最后会汇总放在答案中,各位不要急. 还有,后期会有原创题测试,这个不急,反正11月才 ...

  9. #LOJ2564 SDOI2018 原题识别 主席树

    转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/9057297.html 原题链接: 今天考试考了前天的SDOI考题 天啊我菜爆,只有T2拿了30分 然后考试后半 ...

随机推荐

  1. ASUS主板ALC887声卡,RTL81XX网卡,黑苹果驱动安装

    折腾了一下午终于在黑苹果上成功的安装了网卡,声卡驱动: 我的配置: 主板 ASUS b75m-a 声卡 ALC887 网卡 RTL8168F 安装所需工具: MutiBest 下载OS对应的版本即可  ...

  2. 解决svn Authorization failed错误

    解决svn Authorization failed错误 (2010-09-22 21:37:31) 转载▼   出现该问题基本都是三个配置文件的问题,下面把这个文件列出来 svnserve.conf ...

  3. java 有用的类库

    import org.apache.commons.lang.StringUtils; 字符串库

  4. 【Python 数据分析】module 'numpy' has no attribute 'array'

    安装好Numpy模块后,开始做了几个小测试都可以运行,但是当我创建numpy.py这个文件后 numpy.py import numpy y = numpy.array([[11,4,2],[2,6, ...

  5. 06-spring学习-自动装配

    自动装配前面也有写过.这里只做补充 在之前,对于要引用的属性,都必须写上名称, 原始配置: 当要在emp对象里面引用dept对象的时候,需要明确的使用“ref“属性去找到指定的名称,但是这种操作中也可 ...

  6. php中对象是引用类型吗?

    这貌似是一个极其简单的问题,还用得着专门写一篇博文?各位看官,最初我也这么认为,但这的确蒙蔽了你那水灵灵的小眼睛,不妨看看什么是引用? $a = 10; $b = &$a; $b = 20; ...

  7. 【原创】打造基于Dapper的数据访问层

    [原创]打造基于Dapper的数据访问层   前言 闲来无事,花几天功夫将之前项目里用到的一个数据访问层整理了出来.实现单个实体的增删改查,可执行存储过程,可输出返回参数,查询结果集可根据实际情况返回 ...

  8. WebApi接口传参不再困惑(4):传参详解

    前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料.如今,使用WebApi也有段时间了,今天就记录下API接口传参的一些方式方法,算是一个笔记,也希望能帮初学者少走弯路.本 ...

  9. linux按内容查找文件

    1,在某个路径下查文件. 在/etc下查找“*.log”的文件 find /etc -name "*.log" 2,扩展,列出某个路径下所有文件,包括子目录. find /etc ...

  10. jQuery remove 内存 释放

    解决方案(伪代码):(http://www.cnblogs.com/see7di/archive/2011/09/08/2239653.html)jQuery( “*”, obj).add([obj] ...