P3119 [USACO15JAN]草鉴定[SCC缩点+SPFA]】的更多相关文章

题目描述 约翰有n块草场,编号1到n,这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝西在通一个草场只吃一次草,所以一个草场可以经过多次.因为草场是单行道连接,这给贝西的品鉴工作带来了很大的不便,贝西想偷偷逆向行走一次,但最多只能有一次逆行.问,贝西最多能吃到多少个草场的牧草. 解析 此题就是在Tarjan的板子上玩了点花样,然鹅窝这种题都写不出来,看来我还需要提升. 首先容易看出来一…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way co…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 约翰有\(n\)块草场,编号1到\(n\),这些草场由若干条单行道相连.奶牛贝西是美味牧草的鉴赏家,她想到达尽可能多的草场去品尝牧草. 贝西总是从1号草场出发,最后回到1号草场.她想经过尽可能多的草场,贝西在通一个草场只吃一次草,所以一个草场可以经过多次.因为草场是单行道连接,这给贝西的品鉴工作带来了很大的不便,贝西想偷偷逆向行走一次,但最多只能有一次逆行.问,贝西最多能吃到多少个草场的牧草. 输入输出格式…
P3119 [USACO15JAN]草鉴定Grass Cownoisseur 题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way co…
题面 传送门:https://www.luogu.org/problemnew/show/P3119 Solution 这题显然要先把缩点做了. 然后我们就可以考虑如何处理走反向边的问题. 像我这样的蒟蒻,当然是使用搜索,带记忆化的那种(滑稽). 考虑设f(i,j)表示到达第i个点,还能走j次反向边,所能到达的最多的点的数量. 转移可以表示为: 如果x能到达1所在的强连通分量或max出来的值不为0,说明当前状态可行,否则不可行. 然后用记忆化搜索表达出来就OK了 Code #include<io…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…
题目描述 In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm consists of N fields, conveniently numbered 1..N, with each one-way cow path connecting a pair of fields. For…
首先缩一波点,就变成了一个DAG,边权是出点的大小 那我们走到某个点的时候可能会有两种状态:已经走过反边或者没走过 于是就把一个点拆成两层(x和x+N),第二层的点表示我已经走过反边了,每层中的边和原来一样,但对于边(u,v),我们连一个(v,u+N),表示走了这条边的反边,这条边的边权是u的大小 因为DAG中没有环,所以权值不会被重复计算 然后spfa算从belong[1]到bel[1]+N的最长路就行了 #include<bits/stdc++.h> #define CLR(a,x) me…
http://www.lydsy.com/JudgeOnline/problem.php?id=3887|| https://www.luogu.org/problem/show?pid=3119 Description In an effort to better manage the grazing patterns of his cows, Farmer John has installed one-way cow paths all over his farm. The farm con…