【解题思路】

  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. 【leetcode】bash脚本练习

    [192]Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...

  2. Oracle数据库创建与连接

    一.Oracle数据库的安装 1.下载Oracle数据库 网址:Oracle 数据库软件下载 | Oracle 技术网 | Oracle 由于需要注册,所以我就没有采用这种下载方式,  右击该网页查看 ...

  3. PHP 的 new static 和 new self

    下面我们举个例子: class Father { public static function getSelf() { return new self(); } public static funct ...

  4. 批量更新数据(BatchUpdate)

    批量更新数据(BatchUpdate) /// <summary> /// 批量更新数据,注意:如果有timestamp列,要移除 /// </summary> /// < ...

  5. 【TCP】SYN攻击

    TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...

  6. LOJ6485 LJJ 学二项式定理 解题报告

    LJJ 学二项式定理 题意 \(T\)组数据,每组给定\(n,s,a_0,a_1,a_2,a_3\),求 \[ \sum_{i=0}^n \binom{n}{i}s^ia_{i\bmod 4} \] ...

  7. 高级运维(三):部署Lnmp环境、构建Lnmp平台、地址重写

    一.部署LNMP环境 目标: 安装部署Nginx.MariaDB.PHP环境 1> 安装部署Nginx.MariaDB.PHP.PHP-FPM: 2> 启动Nginx.MariaDB.FP ...

  8. Service3

    RAID阵列概述• 廉价冗余磁盘阵列– 通过硬件/软件技术,将多个较小/低速的磁盘整合成一个大磁盘– 阵列的价值:提升I/O效率.硬件级别的数据冗余– 不同RAID级别的功能.特性各不相同 ##### ...

  9. sublime text3 nodejs控制台输出结果中文乱码

    在sublime text3安装完nodejs的插件后,运行console.log("你好"),发现控制台出现中文乱码,解决办法:Preferences-> Browser ...

  10. css 导航样式

    html  结构 <div class="nav-menu float-r"> <ul class="menu-item"> <l ...