农夫约翰和他的奶牛准备去旅行,所以约翰想要把他的农场临时关闭. 农场有N个牛棚(牛棚从1到N编号),有M条路连接这些牛棚(1≤N,M≤3000). 约翰打算挨个关闭牛棚,在关牛棚的时候, 他突然想起一个有趣的问题:剩余的这些没有关闭的牛棚是不是连通呢? 连通指的是从任何一个牛棚出发,都能到达其他牛棚(注意:已经关闭的牛棚不可以通行). Input 第一行包括两个整数N M, 接下来M行,每行输入两个整数x y,表示x和y牛棚之间存在一条路,路是双向通行的. 接下来n行,表示关牛棚的顺序. Out…
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime. The farm consists of NN barns connected with MM bidirectional paths between some pairs of…
传送门 题目大意: n个谷仓 ,每次关闭一个谷仓,问剩下没被关闭的谷仓是 否联通. 题解:并查集+倒序处理 代码: #include<iostream> #include<cstdio> #include<cstring> #define N 3030 using namespace std; int n,m,sumedge,cnt; int head[N],fa[N],q[N],ans[N],exit[N]; struct Edge{ int x,y,nxt; Edg…
题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime. The farm consists of  barns connected with  bidirectional paths between some pairs of barn…
题目描述 FJ和他的奶牛们正在计划离开小镇做一次长的旅行,同时FJ想临时地关掉他的农场以节省一些金钱. 这个农场一共有被用M条双向道路连接的N个谷仓(1<=N,M<=3000).为了关闭整个农场,FJ 计划每一次关闭掉一个谷仓.当一个谷仓被关闭了,所有的连接到这个谷仓的道路都会被关闭,而且再也不能够被使用. FJ现在正感兴趣于知道在每一个时间(这里的“时间”指在每一次关闭谷仓之后的时间)时他的农场是否是“全连通的”——也就是说从任意的一个开着的谷仓开始,能够到达另外的一个谷仓.注意自从某一个时…
https://www.luogu.org/problem/P3144 每次关闭一个农场,农场之间有边相连,问每次关闭后开着的农场是否是一个连通块: 数据小,离线搞: 我们先记录删的顺序,然后倒着来,先将所有删去的点都标记,每次加点,再把所有没删的都加在一起, in_class[i]==1表示这个点在农场里: 我们从一个删点的过程变成一个加点的过程: 因为在第n次点都删完了,所以一定是一个连通块(体积为0): #include<cstdio> #include<cstring> #…
题目描述 in English: Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to temporarily close down his farm to save money in the meantime. The farm consists of NN barns connected with MM bidirectional paths between so…
P2919 [USACO08NOV]守护农场Guarding the Farm 题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each hill…
题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each hill. He has a map supplied as a matrix of i…
https://www.luogu.org/problem/show?pid=2919 题目描述 The farm has many hills upon which Farmer John would like to place guards to ensure the safety of his valuable milk-cows. He wonders how many guards he will need if he wishes to put one on top of each…
题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵循的穿越路线来确保奶牛的乐趣.为了实现这个让奶牛在牛棚里来回穿梭的方案,FJ在第i号隔间上张贴了一个“下一个隔间”Next_i(1<=Next_i<=N),告诉奶牛要去的下一个隔间:这样,为了收集它们的糖果,奶牛就会在牛棚里来回穿梭了. FJ命令奶牛i应该从i号隔间开始收集糖果.如果一只奶牛回到某…
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected \(N\) diamonds (\(N \leq 50,000\) of varying sizes, and she wants to arrange so…
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected NN diamonds (N \leq 50,000N≤50,000) of varying sizes, and she wants to arrange…
    解法众多的一道毒瘤题? 题目描述 奶牛Bessie很喜欢闪亮亮的东西(Baling~Baling~),所以她喜欢在她的空余时间开采钻石!她现在已经收集了\(N\)颗不同大小的钻石,现在她想在谷仓的两个陈列架上摆放一些钻石. Bessie想让这些陈列架上的钻石保持相似的大小,所以她不会把两个大小相差\(K\)以上的钻石同时放在一个陈列架上(如果两颗钻石的大小差值为\(K\),那么它们可以同时放在一个陈列架上).现在给出\(K\),请你帮Bessie确定她最多一共可以放多少颗钻石在这两个陈列…
P3145 [USACO16OPEN]分割田地Splitting the Field 题目描述 Farmer John's NN cows (3 \leq N \leq 50,0003≤N≤50,000) are all located at distinct positions in his two-dimensional field. FJ wants to enclose all of the cows with a rectangular fence whose sides are pa…
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.…
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.The…
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected NN diamonds (N \leq 50,000N≤50,000) of varying sizes, and she wants to arrange some of them in a pair of display cases in…
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected  diamonds () of varying sizes, and she wants to arrange some of them in a pair of display cases in the barn. Since Bessie…
P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵循的穿越路线来确保奶牛的乐趣.为了实现这个让奶牛在牛棚里来回穿梭的方案,FJ在第i号隔间上张贴了一个“下一个隔间”Next_i(1<=Next_i<=N),告诉奶牛要去的下一个隔间:这样…
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.…
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.The…
P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 分析: 这棵树上有且仅有一个环 两种情况: 1.讨论一个点在环上,如果在则答案与它指向点相同, 2.不在就等于它指向点答案+1,具体就直接大力dfs, 如何求环长度: 终点深度-起点深度=终点起点距离 #include<cstdio> #include<string> #include<cstring> using namespace std; ; int n; ; i…
题目大意:给你一张有向图,每个点最多一条出边,问从每个开始,走多少步会到一个已经过的点 题解:$tarjan$缩点,然后建反图$DP$ 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #define maxn 100010 int head[maxn], cnt; struct Edge { int to, nxt; } e[maxn]; inline void addedge(int a, int b) { e[++cn…
[题解] 就是基环外向树森林找环,然后从环向外统计size就可以了. #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #define LL long long #define rg register #define N 200010 using namespace std; int n,color,top,to[N],siz[N],st[N],pos[N]; bo…
链接: P3147 P3146双倍经验 前言: 今天发现的一道很有意思的DP题 分析: 第一眼以为是区间DP,于是设f[i][j]为从第i个数到第j个数可以合出的最大值,但思考后发现并不能简单合并,并且n的范围也不支持. 于是想贪心,但是贪着贪着发现自己想不出,于是看题解,发现唯一的贪心也被hack了,果然正解不是贪心. 决定放弃. 于是回头重新看题分析,首先根据n的范围分析后可以发现答案范围很小,最大为58,又回到刚开始的区间DP,我们发现其中有三个关键值,左端点,右端点和答案,那么我们可以尝…
FJ和他的奶牛们正在计划离开小镇做一次长的旅行,同时FJ想临时地关掉他的农场以节省一些金钱. 这个农场一共有被用M条双向道路连接的N个谷仓(1<=N,M<=3000).为了关闭整个农场,FJ 计划每一次关闭掉一个谷仓.当一个谷仓被关闭了,所有的连接到这个谷仓的道路都会被关闭,而且再也不能够被使用. FJ现在正感兴趣于知道在每一个时间(这里的“时间”指在每一次关闭谷仓之前的时间)时他的农场是否是“全连通的”——也就是说从任意的一个开着的谷仓开始,能够到达另外的一个谷仓.注意自从某一个时间之后,可…
[洛谷P2921] [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵循的穿越路线来确保奶牛的乐趣.为了实现这个让奶牛在牛棚里来回穿梭的方案,FJ在第i号隔间上张贴了一个"下一个隔间"Next_i(1<=Next_i<=N),告诉奶牛要去…
P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is time to re-paint his farm. The farm consists of N fenced enclosures (1 <= N <= 50,000), each of which can be described by a rectangle in the 2D plane…
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N x N 的方格.输入数据中包括有树的方格的列表.你的任务是计算并输出,在他的农场中,不需要砍树却能够修建的最大正方形牛棚.牛棚的边必须和水平轴或者垂直轴平行. EXAMPLE 考虑下面的方格,它表示农夫约翰的农场,‘.'表示没有树的方格,‘#'表示有树的方格 1 2 3 4 5 6 7 8 1 .…