【解题思路】

  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. 微信小程序分享功能的path路径

    表示被微信小程序坑惨了 糟心的开始写,老板说先不上太复杂,就先显示了两个页面,然后开开心心的发布,测试了几遍,没啥问题呀.结果,一上上去,就被老板批了! 啥呀! 这分享怎么这个鬼样子!明明我看文档都是 ...

  2. vue全家桶(vue2.x+vue-router+axios+webpack)项目搭建

    参考博客文章 博主FungLeo的Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版 注:原博主写的非常详细 本文章为根据原博主教程总结的自己的搭建流程 一.安装n ...

  3. 【JavaWeb项目】一个众筹网站的开发(五)后台用户登录功能

    用户模块 1)注册 表单校验,使用校验插件 用户密码需要加密存储 注册成功后来到管理控制台,将用户放在session中,防止以后获取 以后用户经常获取用户id,使用mabatis主键自增策略,保存用户 ...

  4. 【leetcode】962. Maximum Width Ramp

    题目如下: Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. ...

  5. YIi2中checkboxOptions前选框的用法

    这是checkboxOptions前选框的用法 use yii\grid\GridView; $this->registerJs(" $('#selection_all').click ...

  6. CSS3布局篇(多列布局)

    我们通过学习 CSS3,能够创建多个列来对文本进行布局 ,就像报纸那样排版那样! 可以参考详细说明:http://www.w3school.com.cn/css3/css3_multiple_colu ...

  7. 帝国CMS数据库数据表详细说明

    表名                                             解释 phome_ecms_infoclass_news 新闻采集规则记录表 phome_ecms_inf ...

  8. 【Flutter学习】基本组件之文本组件Text

    一,概述 文本组件(Text)负责显示文本和定义显示样式, 二,继承关系 Object > Diagnosticable > DiagnosticableTree > Widget ...

  9. svn 类似.gitignore功能实现

    svn propset -R svn:ignore -F .cvsignore .

  10. GF学习未解之谜

    1.很奇怪事件管理器里面的用到的订阅事件里面的ID是通过typeof(xxx).GetHashCode()得到的,怎么解决id重复的问题? 2.log系统里面是不是直接全部当做多参数解决问题比较好?