//我看过Discuss说不能用克鲁斯卡尔因为有很多边
//但是只能用G++过,C++的确超时
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; struct node
{
int a, b, cost;
}c[];
int fa[]; void init(int n)
{
for (int i = ; i <= n; i++)
fa[i] = i;
} bool cmp(node x, node y)
{
return x.cost<y.cost;
} int find(int x)
{
if (fa[x] != x) fa[x] = find(fa[x]);
return fa[x];
} int main()
{
int n, k, m, ncase;
scanf("%d", &ncase);
while (ncase--)
{
scanf("%d %d %d", &n, &k, &m);
init(n); //初始化
for (int i = ; i<k; i++)
scanf("%d %d %d", &c[i].a, &c[i].b, &c[i].cost);
for (int i = ; i <= m; i++)
{
int x, pos, pos1;
scanf("%d %d", &x, &pos);
for (int j = ; j<x; j++)
{
scanf("%d", &pos1);
c[k].a = pos, c[k].b = pos1, c[k].cost = ;
pos = pos1;
k++;
}
} sort(c, c + k, cmp);
int sum = ;
for (int i = ; i<k; i++)
{
int x = find(c[i].a);
int y = find(c[i].b);
if (x != y)
sum += c[i].cost, fa[x] = y;
} int count = ;
for (int i = ; i <= n; i++)
if (fa[i] == i)
count++; if (count != )
printf("-1\n");
else
printf("%d\n", sum);
}
return ;
}

最新文章

  1. excel 两列比较内容是否相同
  2. 从vs2010的UnitTestFramework类库提取私有方法反射调用的方法
  3. 使用 Daynamic 动态添加属性
  4. 利用K2和Microsoft Dynamics CRM构建业务App的5大理由
  5. 【JavaScript】重温Javascript继承机制
  6. 深刻理解Python中的元类(metaclass)
  7. 关于ASE日志空间示数不正常的解决办法
  8. MapReduce多用户任务调度器——容量调度器(Capacity Scheduler)原理和源码研究
  9. Q我音乐
  10. [译] 新手和老手都将受益的JavaScript小技巧
  11. Python的多线程编程
  12. Photoshop颜色出现比较大的偏差,偏色严重,显示器配置文件2351似乎有问题
  13. 使用hue查看hdfs系统报无法访问:/user/hadoop。 Note: you are a Hue admin but not a HDFS superuser, &quot;hdfs&quot; or part of HDFS supergroup, &quot;supergroup&quot;.
  14. Android Studio相关资料链接
  15. HTMLCSS--案例| 超链接美化 | 模态框 | tab栏选项卡
  16. 【python】升级pip后报错解决pkg_resources.DistributionNotFound: The &#39;pip==7.1.0&#39; distribution was not found and is required by the application
  17. SQL中的 if 结构和循环(while)结构
  18. 微软BI 之SSIS 系列 - 理解Data Flow Task 中的同步与异步, 阻塞,半阻塞和全阻塞以及Buffer 缓存概念
  19. 其它终端设备连接gmail账户提示密码错误解决方法
  20. GitLab使用自定义端口

热门文章

  1. opencvSGBM半全局立体匹配算法的研究(1)
  2. Umbrella Header for Module Bolts does not include header &amp;#39;XXXXXX.h&amp;#39;?
  3. mac系统不同java版本切换
  4. python day-15 匿名函数 sorted ()函数 filter()函数 map()函数 递归 二分法
  5. NettyIO
  6. HDFS运维和优化
  7. mysql优化-----索引覆盖
  8. 一个基本的spring+mybatis所需要的包
  9. 鼠标滑过TAB选项卡切换demo 可拓展
  10. js操作创建和操作外部样式的例子