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. draw call 理解和优化

    draw call是openGL的描绘次数(directX没怎么研究,但原理应该差不多)一个简单的openGL的绘图次序是:设置颜色→绘图方式→顶点座标→绘制→结束.每帧都会重复以上的步骤.这就是一次 ...

  2. 解决ios7.0 以后自己定义导航栏左边button靠右的问题

    1.自己定义button //左button UIButton *leftBtn = [[UIButton , , , )]; [leftBtn addTarget:self action:@sele ...

  3. Windows下如何安装 Composer

    如何安装 Composer Windows下如何安装 Composer 下载 Composer 安装前请务必确保已经正确安装了 PHP.打开命令行窗口并执行 php -v 查看是否正确输出版本号. 打 ...

  4. jConsole,jvisualvm和jmap使用

    JConsole     JConsole 是一个内置 Java 性能分析器,可以从命令行或在 GUI shell 中运行.可以轻松地使用 JConsole来监控 Java 应用程序性能和跟踪 Jav ...

  5. Java 连接 Oracle 数据库

    首先要导入ojdbc6.jar 包(放在lib文件夹) 然后需要在数据库建一个student表进行测试: 连接及测试代码: import java.security.interfaces.RSAKey ...

  6. java基础讲解07-----数组

    1.什么是数组 2.怎么使用数组 package test; public class ShuZu {            public static void main(String[] args ...

  7. 基于AndroidPn二次开发的可行性

    一.背景 如果要自己搭建,从零开始做或基于开源进行修改扩充,开源的push引擎,90%的博文首推AndroidPN,结合公司现状,最优解决方案就是进行AndroidPN的二次开发了.先看一下这个项目: ...

  8. 通过SectionIndexer实现微信通讯录

    这里主要参考了使用SectionIndexer实现微信通讯录的效果 在这里做个记录 效果图 页面使用RelativeLayout,主要分为三个部分,match_parent的主listView,右边字 ...

  9. linux下查看cc攻击

    什么是CC攻击?CC攻击就是利用大量代理服务器对目标计算机发起大量连接,导致目标服务器资源枯竭造成拒绝服务.那么如何判断查询CC攻击呢?本文主要介绍了一些Linux下判断CC攻击的命令. 查看所有80 ...

  10. Mongodb更新数组$sort操作符

    db.students.update( { _id: 1 }, { $push: { quizzes: { $each: [ { id: 3, score: 8 }, { id: 4, score:  ...