额   最小生成树 ........

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
int u,v,len;
void f(int i, int j, int k)
{
u = i, v = j;
len = k;
}
bool operator < (const node &p) const
{
return len < p.len;
}
};
node cc[300020];
int f[1010];
int find(int x)
{
return f[x] == x ? x : f[x] = find(f[x]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int p,n,m;
scanf("%d%d%d",&p,&n,&m);
for(int i = 1; i <= n; i++)
f[i] = i;
for(int i = 0; i < m; i++)
{
int x,y,len;
scanf("%d%d%d",&x,&y,&len);
cc[i].f(x, y, len);
}
sort(cc, cc+m);
int ans = 0;
for(int i = 0; i < m; i++)
{
int x = find(cc[i].u), y = find(cc[i].v);
if(x != y)
{
ans += cc[i].len;
f[x] = y;
}
}
printf("%d\n",ans*p);
}
return 0;
}

spoj 368的更多相关文章

  1. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  2. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  5. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  6. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  7. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  8. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  9. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

随机推荐

  1. Xcode Product -> Archive disabled

    You've changed your scheme destination to a simulator instead of "iOS Device". That's why ...

  2. 一些C++内容的总结(2013.10.17)

    1.using namespace std;使用的是C++标准库当中的一些变量,比如cout,cin等.但是using namespace std作用域只对当前文件内作用,所以using namesp ...

  3. CSS常用中文字体、字号

    字体(font-family): 新细明体:PMingLiU 细明体:MingLiU 标楷体:DFKai-SB 黑体:SimHei 宋体:SimSun 新宋体:NSimSun 仿宋:FangSong  ...

  4. UML静态类图

    0,主要分为类.接口.协作.关系,这四种元素.作用:a,显示类.接口以及他们之间的静态结构和关系:b,用于描述系统的结构化设计. 1,类 CStudent +m_strName : string +S ...

  5. linux 运维知识体系

    这里将会介绍一下,LINUX运维工程师的知识体系. 只能说是个人理解吧.并不是必要或者充分的,仅供网友参考. 大部分本博客都有涉及,并不完整. 1.LINUX运维基础 1.1.LINUX系统的简介,分 ...

  6. WinForms 实现气泡提示窗口

    [实例说明] 气泡提示因为他的美观又好被大多数用户所接收,用户所喜爱的就是程序员要实现的. 本实例实现了任务栏气泡提示,运行本实例,效果图如下所示: 单击提示.气泡提示就会显示,单击“关闭”气泡又会消 ...

  7. JS中如何判断null

    var exp = null; if (exp == null) { alert("is null"); } exp 为 undefined 时,也会得到与 null 相同的结果, ...

  8. spark(一) build

    (1)编译前的准备工作,安装jdk,解压maven,解压spark,解压scala并配置相关的环境变量 export JAVA_HOME=/opt/module/jdk1.6.0_45 export ...

  9. linux 输入子系统(4)---- input子系统的初始化

    Input子系统的初始化函数为input_init(),如下: static int __init input_init(void) { int err; input_init_abs_bypass( ...

  10. nodejs的模块系统(实例分析exprots和module.exprots)

    前言:工欲善其事,必先利其器.模块系统是nodejs组织管理代码的利器也是调用第三方代码的途径,本文将详细讲解nodejs的模块系统.在文章最后实例分析一下exprots和module.exprots ...