【解题思路】

  Kruskal的拓展。

  可以先对边排序,进行一次Kruskal,判断是否可行,并计算出每种权值的边需要多少条。

  然后暴力统计每种权值可行的方案数,根据乘法原理乘起来即可。复杂度o(210mlog2(m+α(n)))。

【参考代码】

 #pragma GCC optimize(2)
#include <algorithm>
#define REP(i,low,high) for(register int i=(low);i<=(high);++i)
using namespace std; //quick_io {
#include <cctype>
#include <cstdio>
inline long long getint()
{
char ch=getchar(); for(;!isdigit(ch)&&ch!='+'&&ch!='-';ch=getchar());
short sig=; for(;ch=='+'||ch=='-';ch=getchar()) if(ch=='-') sig*=-;
long long ret=; for(;isdigit(ch);ch=getchar()) ret=(ret<<)+(ret<<)+ch-'';
return sig*ret;
}
//} quick_io //find_union_set {
#include <cstring>
class find_union_set
{
private:int fat[],stk[];
int find(const int&element)
{
int ancestor=element,top=;
for(;ancestor!=fat[ancestor];ancestor=fat[ancestor]) stk[top++]=ancestor;
for(;top--;fat[stk[top]]=ancestor); return ancestor;
}
public:
find_union_set() {REP(i,,) fat[i]=i;} void clear() {REP(i,,) fat[i]=i;}
find_union_set&operator=(const find_union_set&thr)
{
return memcpy(fat,thr.fat,sizeof thr.fat),*this;
}
bool same(const int&one,const int&thr) {return find(one)==find(thr);}
bool unite(const int&one,const int&thr)
{
return same(one,thr)?:(fat[fat[one]]=fat[thr],);
}
};
//} find_union_set struct edge
{
int fr,to,vl;
void input() {fr=getint(),to=getint(),vl=getint();}
bool operator<(const edge&thr)const{return vl<thr.vl;}
}edg[]; static const int AwD=; int cnt[]={}; find_union_set now,tmp,can;
int main()
{
int n=getint(),m=getint(); REP(i,,m) edg[i].input(); sort(edg+,edg+m+);
int tot=,ans=; REP(i,,m)
{
tot+=edg[i].vl!=edg[i-].vl;
if(!now.same(edg[i].fr,edg[i].to)) now.unite(edg[i].fr,edg[i].to),++cnt[tot];
}
REP(i,,n) if(!now.same(,i)) return puts(""),; now.clear();
for(register int i=,j=,tot=;i<=m;i=++j,++tot,now=can)
{
for(;j<=m&&edg[j].vl==edg[i].vl;++j); --j; int count=;
for(register int status=<<j-i+;status--;)
if(__builtin_popcount(status)==cnt[tot])
{
tmp=now; bool flag=; REP(k,i,j) if(status&(<<k-i))
{
if(flag=!tmp.unite(edg[k].fr,edg[k].to)) break;
}
if(!flag) {can=tmp; if(++count==AwD) count=;}
}
(ans*=count)%=AwD;
}
return printf("%d\n",ans),;
}

bzoj1016题解的更多相关文章

  1. BZOJ1016:[JSOI2008]最小生成树计数——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=1016 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不 ...

  2. 【bzoj1016】 JSOI2008—最小生成树计数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1016 (题目链接) 题意 求图的最小生成树计数. Solution %了下题解,发现要写矩阵树,15 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  5. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  6. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  7. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  8. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

随机推荐

  1. web.xml中配置——解决post乱码

    <!-- 解决post乱码 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> ...

  2. python 文件复制压缩

    import os import time #这里是需要文件所在的位置 source=['"C:\\My Documents"',"C:\\Code"] #转换 ...

  3. kubeadm部署多master节点高可用k8s1.16.2

    一.架构信息 系统版本:CentOS 7.6 内核:3.10.0‐1062.4.1.el7.x86_64 Kubernetes: v1.16.2 Docker­ce: 19.03 推荐硬件配置:2核4 ...

  4. 关于axios中post请求提交后变成get的问题

    这个问题归结于自己的不细心,如下图. 头疼了好久,才发现是自己多写了一个s,在此记录一下.

  5. ImsConference.java中会议成员更新处理详解

    public class ConferenceParticipant implements Parcelable { //自定义数据结构 private static final String ANO ...

  6. Feign 系列(05)Spring Cloud OpenFeign 源码解析

    Feign 系列(05)Spring Cloud OpenFeign 源码解析 [TOC] Spring Cloud 系列目录(https://www.cnblogs.com/binarylei/p/ ...

  7. ThinkPHP5验证码不显示的原因及解决方法

    其实很久之前刚学习tp5框架的时候就遇到了这个问题,解决完后一直没再出过问题,今天用以前的框架做新项目时又碰到了这个问题,这里记录一下 问题原因: 1.TP5本就存在这个bug 2.数据库连接不正常( ...

  8. 36-Ubuntu-用户管理-01-新建用户useradd

    创建用户/设置密码/删除用户/确认用户信息 序号 命令 作用 说明 01 sudo useradd -m -g 组名 新建用户名 添加新用户 -m 自动建立用户家目录 -g 指定用户所在的组,否则会建 ...

  9. 第十篇 scrapy item loader机制

    在我们执行scrapy爬取字段中,会有大量的和下面的代码,当要爬取的网站多了,要维护起来很麻烦,为解决这类问题,我们可以根据scrapy提供的loader机制 def parse_detail(sel ...

  10. oracle运维(持续更新)

    目录 简单命令使用 进入SQL*Plus 退出SQL*Plus 在sqlplus下得到帮助信息 显示表结构命令 DESCRIBE SQL*Plus 中的编辑命令 调用外部系统编辑器 运行命令文件 关于 ...