摘要:
LCA应用求最短路 #include<cstdio> #include<iostream> #include<cstring> using namespace std; const int N=40005; int T,n,m,ans,tot; struct node{ int to,next,w; 阅读全文
摘要:
将计数融入最短路中,即 if(dis[v]==dis[u]+edge[i].w){ ans[v]+=ans[u]; ans[v]%=mod; } #include<cstdio> #include<iostream> #include<cstring> #include<queue> using n 阅读全文
摘要:
分层图最短路,注意数组范围 #include<cstdio> #include<iostream> #include<cstring> #include<queue> using namespace std; const int N=2000005; int n,m,tot,k; bool vis[ 阅读全文
摘要:
每合并一次,部落数减一,最终合并到合法的数量。 若i时得到nk时,不能确定w[i+1]即为答案,因为可能u[i+1].fv[i+1].f,所以还需要再往下枚举判断。 #include<cstdio> #include<iostream> #include<cstring> #include<cmat 阅读全文
摘要:
欧几里得距离不需要开根号,题目描述联通的最小代价指的是和。 细节: 1.因为克鲁斯卡尔算法枚举的是边,所以不需要在意是无向图,仅存一遍即可,即32、33行,j直接从i+1开始枚举。 2.最后判断时,如果tot==n-1,让其break,再外面再进行其他操作会更快一些。 #include<cstdio 阅读全文
摘要:
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int N=505; int s,p,tot,cnt; struc 阅读全文
摘要:
分层图最短路 范围要开的足够大 注意: add(u+j * n,v+j * n,w); add(v+j * n,u+j * n,w); add(u+(j-1) * n,v+j * n,0); add(v+(j-1) * n,u+j * n,0); 最后终点之间连上边权为0的边 #include<cs 阅读全文
摘要:
题目链接:https://www.luogu.com.cn/problem/P2758 设f[i][j]表示把A中[1,i]变成B中[1,j]的最小操作数。 如果A[i]==B[j],那么直接转移。 否则有三种情况: f[i][j]=f[i-1][j-1],把A[i]换成B[j] f[i][j]=f 阅读全文
摘要:
题目链接:https://www.luogu.com.cn/problem/P1970 AC代码: 1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 const int N=100010; 5 int a[N],f[N] 阅读全文
摘要:
题目链接:https://www.luogu.com.cn/problem/P6154 拓扑排序+快速幂求逆元 AC代码: 1 #include<cstdio> 2 #include<iostream> 3 #include<queue> 4 #include<cstring> 5 using na 阅读全文