An undirected connected graph has $n$ nodes and $m$ edges, The $i$-th edge’s length is $2^i$. Each node $i$ has a value $a_i$, which is either $0$ or $1$. You need to calculate:

$$
\sum_{i=1}^{n}\sum_{j=1}^{n}d(i,j)\times [a_i=1\wedge a_j=0]
$$

$d(i,j)$ indicates the shortest distance between $i$ and $j$. $[\ ]$ is the Iverson bracket. $\wedge$ indicates $\texttt{AND}$.

Because the answer may be too large, please output the answer modulo $10^9 + 7$.

InputThe first line contains one integer $T$($1\le T \le 8$),indicating the number of test cases.

The second line contains two ingeters $n,m$($1\le n\le 10^5,1\le m\le 2\times 10^5$).

The third line contains $n$ positive integers $a_1,a_2,...,a_n(a_i = 0$ or $1$) —— the value of the nodes.

The following $m$ lines contain two ingeters $u,v(1
\le u,v \le n)$, and the $i$-th line represents the i-th undirected edge’s length is $2^i$, between node $u$ and $v$.

The sum of $n,m$ is no more than $2\times 10^5$.OutputPrint a single integer—— the value of the answer modulo $10^9+7$.Sample Input

1
3 2
0 1 0
3 1
3 2

Sample Output

10

Sponsor

题意:

给出一个无向连通图,里面的点分为0号点和1号点,第i条边的边权是2的i次。

询问所有1号点到0号点的最短路径之和。

题解:

  建树,最短路径都在图的最小生成树上

  统计单边的贡献:

    一边跑一边计数 乘上边权值

附代码(未通过,待解决)

 

  

F - A Very Easy Graph Problem HDU - 6832 未解决的更多相关文章

  1. hdu 6832 A Very Easy Graph Problem 构造树+dfs

    题意: 给你一个n个点m条边的图,对于第i条边,它的长度是2i,对于每一个顶点,它不是0类型,就是1类型.你需要找出来对于所有的"两个不同类型的点之间最短距离"的和 题解(参考:h ...

  2. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  3. HDU 5572--An Easy Physics Problem(射线和圆的交点)

    An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  4. hdu 5572 An Easy Physics Problem 圆+直线

    An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  5. UVA11069 - A Graph Problem(DP)

    UVA11069 - A Graph Problem(DP) 题目链接 题目大意:给你n个点.要你找出有多少子串符合要求.首先没有连续的数字,其次不能再往里面加入不论什么的数字而不违反第一条要求. 解 ...

  6. Flow Problem HDU - 3549

    Flow Problem HDU - 3549 Network flow is a well-known difficult problem for ACMers. Given a graph, yo ...

  7. D - Ugly Problem HDU - 5920

    D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...

  8. Prime Ring Problem HDU - 1016 (dfs)

    Prime Ring Problem HDU - 1016 A ring is compose of n circles as shown in diagram. Put natural number ...

  9. 【HDU 5572 An Easy Physics Problem】计算几何基础

    2015上海区域赛现场赛第5题. 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B.A(均在圆外),向量 ...

  10. HDU - 5572 An Easy Physics Problem (计算几何模板)

    [题目概述] On an infinite smooth table, there's a big round fixed cylinder and a little ball whose volum ...

随机推荐

  1. maven导入org.apache.pdfbox

    PDF和图片相互转换用到的maven依赖如下: <dependency> <groupId>org.apache.pdfbox</groupId> <arti ...

  2. JavaWeb 中的 HTTP 基础知识

    概念:超文本传输协议,规定了浏览器和服务器之间数据传输的规则. 特点: 基于TCP协议,面向连接,更安全 基于请求-响应模型,一次请求对应一次响应 是无状态的协议,对事务处理没有记忆能力.每次请求-响 ...

  3. Java IO<2> 输入/输出流 FileInputStream/FileOutputStream

    输入/输出流 按操作 数据单位不同分为:流 字节流(8 bit) ,字符流(16 bit) 按数据流的 流向不同分为: 输入流,输出流 按流的 角色的不同分为:节点流,处理流 ![image-2 ...

  4. 在工具类静态方法调用@Autowired注入的bean方法

    今天在搞一个工具类的时候,需要在工具类的静态方法中调用mapper的方法插入数据,但是,用spring的@Autowired注入bean后,测试一跑,报空指针异常. 解决方案如下: 1.对工具类使用@ ...

  5. 三分钟带你了解一站式大数据平台运维管家ChengYing产品包制作

    课件获取:关注公众号 "数栈研习社",后台私信 "ChengYing" 获得直播课件 视频回放:点击这里 ChengYing 开源项目地址:github 丨gi ...

  6. Vue2和Vue3的差异化(通俗易懂)

    一.相同点 响应式系统(Reactive) 两者都采用 "模板 + 响应式" 的开发模式,视图自动随着状态变化而更新. 都支持双向绑定(v-model).条件渲染(v-if/v-s ...

  7. [abc302f] Merge Set

    F - Merge Set 显然要建图 首先,我们有一个粗略的想法,对于同一集合\(S_i\)内的元素,\(S_{i,j}\)与\(S_{i,j+1}\)间连一条无向的标号为\(i\)的边 那么题目显 ...

  8. 快速创建SQL Server 链接服务器

    SQL Server链接服务器简介 SQL Server提供链接到另一个服务器的选项.这通常被用来连接到其他SQL Server数据库,但它也可以被用来连接到一个Microsoft Access数据库 ...

  9. 20w奖金池!魔乐社区国产算力应用创新大赛正式启程

    本文分享自魔乐社区公众号<​​20w奖金池!魔乐社区国产算力应用创新大赛正式启程​​> 当国产算力崛起成为 AI 发展新引擎,你是否渴望用创新方案解锁无限可能?魔乐社区国产算力应用创新大赛 ...

  10. Kong入门学习实践(3)路由转发

    最近在学习Kong网关,因此根据老习惯,我会将我的学习过程记录下来,一来体系化整理,二来作为笔记供将来翻看.由于我司会直接使用Kong企业版,学习过程中我会使用Kong开源版. 本篇,我们学习快速配置 ...