![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
强连通分量
Love_xyh
这个作者很懒,什么都没留下…
展开
-
CF427C Checkposts
记录每个强连通分量中,最小值与最小值个数。 #include <bits/stdc++.h> #define int long long using namespace std; const int N=3e5+5,MOD=1e9+7; int n,m,u,v,ans1,ans2; int now,top,col,dfn[N],low[N],sta[N],color[N],minn[N],sum[N],a[N]; int cnt,head[N]; struct edge{int next,to原创 2020-09-21 20:15:21 · 125 阅读 · 1 评论 -
CF1000E We Need More Bosses
对无向图进行缩点后求树直径即为答案。 #include <bits/stdc++.h> using namespace std; const int N=3e5+5; int n,m,u[N],v[N],ans,p; int now,top,col,dfn[N],low[N],sta[N],color[N]; int cnt=1,head[N]; struct edge{int next,to; bool vis;}e[N<<1]; inline void add(int u,int原创 2020-09-21 20:14:13 · 156 阅读 · 0 评论 -
CF999E Reachability from the Capital
对于缩点后得到的DAG,我们求出入度为0的强连通分量的个数,即为最少的需要添加的边。(注意判断首都所在的强连通分量的入度) #include <bits/stdc++.h> using namespace std; const int N=5e3+5; int n,m,s,u[N],v[N],ans,du[N]; int now,top,col,dfn[N],low[N],sta[N],color[N]; int cnt,head[N]; struct edge{int next,to;}e[N原创 2020-09-21 20:08:53 · 104 阅读 · 0 评论 -
[POI2011]KON-Conspiracy
根据2-SAT模型建边后,可以得到两个组分别是:一个团和一个独立集。 之后需要思考的就是有多少种不同的方案数。 我们发现,对于团和独立集,我们每次只能最多各自拿出一个点,放到对方中去(当然可以不拿)。而由于n恰好满足n^2的数据范围,所以,我们枚举从团中拿出放到独立集中的点,和从独立集中拿出放到图那种的点,n ^2判断操作后是否能满足条件即可。 #include <bits/stdc++.h> using namespace std; const int N=5e3+5; int n; bool原创 2020-09-14 11:57:08 · 168 阅读 · 0 评论 -
UVA1391 Astronauts
每个宇航员只能根据年龄情况,分配A,B中的一个任务,和C任务。 考虑两个有矛盾的宇航员: 1.如果他们在不同年龄区段,那么他们只要不同时在C即可。(即,若其中一人在C,另一个必须在A或B) 2.如果他们在同一年龄区段,那么,当其中一人在A或B时,另一人必须去C。多了两个限制条件。 #include <bits/stdc++.h> using namespace std; const int N=1e5+5; int n,m,x,y,sum,a[N]; int now,top,col,dfn[N*原创 2020-09-14 11:44:04 · 138 阅读 · 0 评论 -
[HNOI2010]平面图判定
根据哈密顿回路的顺序,建立虚拟坐标,后根据虚拟坐标判断两不在回路上的边是否相交。若相交,则两条边必须:一条在内一条在外。根据2-SAT建边即可。 注意边数为10000,但根据平面图性质,m<=3*n-6,所以对于边数不满足性质的情况,直接判断不可行。 #include <bits/stdc++.h> using namespace std; const int N=605,M=8e5+5; int T,n,m,tot,a[10005],b[10005],c[N],id[N],vec[N];原创 2020-09-14 11:39:59 · 1001 阅读 · 0 评论 -
UVA1146 Now or later
二分枚举答案,2-SAT检验是否可行。 #include <bits/stdc++.h> using namespace std; const int N=2e3+5; int n,l,r,mid,ans,tot,a[N*2]; struct number{int x,y;}num[N]; int now,top,col,dfn[N*2],low[N*2],sta[N*2],color[N*2]; int cnt,head[N*2]; struct edge{int next,to;}e[N*N原创 2020-09-14 11:35:44 · 117 阅读 · 0 评论 -
[POI2001]和平委员会
建边如下图: #include <bits/stdc++.h> using namespace std; const int N=8e3+5,M=2e4+5; int n,m,x,y; int now,top,col,dfn[N<<1],low[N<<1],sta[N<<1],color[N<<1],fr[N<<1]; int cnt,head[N<<1]; struct edge{int next,to;}e[M<原创 2020-09-13 12:08:04 · 238 阅读 · 0 评论 -
CF875C National Property
根据2-SAT的方法建图后,得到强连通分量,并根据与拓扑序联系,输出答案。 代码中用详细注释。 #include <bits/stdc++.h> using namespace std; const int N=1e5+5,M=1e5+5; int n,m,ans,a[N],b[N]; int cnt,head[N<<1]; int col,now,top,dfn[N<<1],low[N<<1],color[N<<1],sta[N<<1原创 2020-09-13 10:46:38 · 192 阅读 · 0 评论 -
洛谷 P4782 【模板】2-SAT 问题
2-SAT问题可以通过强连通分量来判断条件是否矛盾。 而题目往往会要求输出方案,输出方案时,强连通分量的scc值,会和原图的拓扑序紧密联系在一起。 #include <bits/stdc++.h> using namespace std; const int N=1e6+5; int n,m,a,b,nowa,nowb; int cnt,head[N<<1]; int col,now,top,dfn[N<<1],low[N<<1],color[N<<原创 2020-09-13 10:30:09 · 161 阅读 · 0 评论 -
CF467D Fedor and Essay
由于某些字符,会我转为你,你转为他,他转为我,形成一个环,所以先缩点后得到一个DAG森林。 对于森林里的每棵树,做一次取最大值的dp即可。 #include <bits/stdc++.h> #define int long long using namespace std; const int N=6e5+5; int n,m,tot,ans1,ans2,id[N],dp1[N],dp...原创 2020-03-27 23:42:56 · 126 阅读 · 0 评论 -
BZOJ 1051: [HAOI2006]受欢迎的牛
仅解释一下tarjan缩点的模板。 #include <bits/stdc++.h> using namespace std; const int N=1e4+5,M=5e4+5; int n,m,u,v,ans,sum; int du[N]; int now,top,col,dfn[N],low[N],sta[N],si[N],color[N]; int cnt,head[N]; ...原创 2020-02-28 21:41:33 · 117 阅读 · 0 评论