Disillusioning #1 水题+原题赛(被虐瞎)
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 水题+原题赛(被虐瞎)的更多相关文章
- NOIP2018初赛普及组原题&题解
NOIP2018初赛普及组原题&题解 目录 NOIP2018初赛普及组原题&题解 原题&答案 题解 单项选择题 第$1$题 第$2$题 第$3$题 第$4$题 第$5$题 第$ ...
- 2019.3.16 noiac的原题模拟赛
RT,这太谔谔了,我不承认这是模拟赛 但是虽然是搬了三道题,题目本身也还能看,就这么着吧 (怎么机房里就我一道原题都没做过啊 T1 CF24D Broken Robot 比较简单地列出式子之后,我们发 ...
- [原题复现][2020i春秋抗疫赛] WEB blanklist(SQL堆叠注入、handler绕过)
简介 今天参加i春秋新春抗疫赛 一道web没整出来 啊啊啊 好垃圾啊啊啊啊啊啊啊 晚上看群里赵师傅的buuoj平台太屌了分分钟上线 然后赵师傅还分享了思路用handler语句绕过select过滤.. ...
- Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100) rec ...
- (各个公司面试原题)在线做了一套CC++综合測试题,也来測一下你的水平吧(二)
刚才把最后的10道题又看了下.也发上来吧. 以下给出试题.和我对题目的一些理解 前10道题地址 (各个公司面试原题)在线做了一套CC++综合測试题.也来測一下你的水平吧(一) 11.设已经有A,B,C ...
- NOIP原题 斗地主(20190804)
题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关 系根据牌的数码表示如下:3<4&l ...
- [CF676C]Vasya and String(尺取法,原题)
题目链接:http://codeforces.com/contest/676/problem/C 原题题解链接:http://www.cnblogs.com/vincentX/p/5405468.ht ...
- NOIP2016原题终结测试(2017081801)
NOIP2016还有几道原题没有写掉,今天就一并布置掉. 答案的问题,有部分会先放到NOIP题解中,是单独发布的. 最后会汇总放在答案中,各位不要急. 还有,后期会有原创题测试,这个不急,反正11月才 ...
- #LOJ2564 SDOI2018 原题识别 主席树
转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/9057297.html 原题链接: 今天考试考了前天的SDOI考题 天啊我菜爆,只有T2拿了30分 然后考试后半 ...
随机推荐
- DataBase 之 拉链表结构设计
一.概念 拉链表是针对数据仓库设计中表存储数据的方式而定义的,顾名思义,所谓拉链,就是记录历史.记录一个事物从开始,一直到当前状态的所有变化的信息. 在历史表中对客户的一生的记录可能就这样几条记录,避 ...
- bootstrap 页面标题
页面标题会突出显示,当一个网页中有多个标题且每个标题之间需要添加一定的间距时,页面标题显得特别有用,页面标题会给不是页面标题之间的元素加上横线 加以区分,以突出标题显示. 页面标题类 显示效果图 代码 ...
- CentOS安装rz\sz命令
执行以下命令进行安装: yum install lrzsz 安装完成后即可操作rz和sz命令. rz:本地文件上传. sz:Linux系统文件下载到本地.
- Phone
User-Agent Switcher for Chrome EditThisCookie cornerstone SVN
- 利用dd命令制作u盘iso镜像
现在安装系统都是用u盘安装,那么制作u盘的iso镜像就是必须的了.现在此类工具倒是不少,但是,好用的不多,有的还收费.唉,还是用dd吧,老配方,老味道. 首先:要df -h一下,看看u盘的盘符,类似 ...
- Atitit。 沉思录 与it软件开发管理中的总结 读后感
Atitit. 沉思录 与it软件开发管理中的总结 读后感 1. <沉思录>,古罗马唯一一位哲学家皇帝马可·奥勒留所著 2 2. 沉思录与it软件开发管理中的总结 2 2.1. 要有自己的 ...
- Struts2请求流程图
ServletContext中的内容: <s:property value="#attr['countries']['cn']"/> <br> Sessio ...
- 大型站点技术架构PDF阅读笔记(一):
1.数据库读写分离: 2.系统吞吐量和系统并发数以及系统响应时间之间的关系: 3.系统负载的概念: 4.反向代理的概念: 5.使用缓存来读取数据: 6.利用cookie来记录session: 利用co ...
- Java序列化与反序列化学习(二):序列化接口说明
一.序列化类实现Serializable接口 Serializable接口没有方法,更像是个标记.有了这个标记的Class就能被序列化机制处理. ObjectOutputStream只能对Serial ...
- redis命令_ZREVRANGEBYSCORE
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] 返回有序集 key 中, score 值介于 max 和 min 之间(默 ...