F - A Very Easy Graph Problem HDU - 6832 未解决

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号点的最短路径之和。

题解:

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

  统计单边的贡献:

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

 

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

 

  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YukiRinLL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值