摘要: 将计数融入最短路中,即 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 阅读全文
posted @ 2021-05-23 16:55 dfydn 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 分层图最短路,注意数组范围 #include<cstdio> #include<iostream> #include<cstring> #include<queue> using namespace std; const int N=2000005; int n,m,tot,k; bool vis[ 阅读全文
posted @ 2021-05-23 16:37 dfydn 阅读(32) 评论(0) 推荐(0) 编辑
摘要: 每合并一次,部落数减一,最终合并到合法的数量。 若i时得到nk时,不能确定w[i+1]即为答案,因为可能u[i+1].fv[i+1].f,所以还需要再往下枚举判断。 #include<cstdio> #include<iostream> #include<cstring> #include<cmat 阅读全文
posted @ 2021-05-23 16:04 dfydn 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 欧几里得距离不需要开根号,题目描述联通的最小代价指的是和。 细节: 1.因为克鲁斯卡尔算法枚举的是边,所以不需要在意是无向图,仅存一遍即可,即32、33行,j直接从i+1开始枚举。 2.最后判断时,如果tot==n-1,让其break,再外面再进行其他操作会更快一些。 #include<cstdio 阅读全文
posted @ 2021-05-23 15:12 dfydn 阅读(39) 评论(0) 推荐(0) 编辑