3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 69 Solved: 49
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2 3
1 3 7
2 3 10
2 4 4
2 5 8
3 4 6
3 5 2
4 5 17
Sample Output
连接4和5,2和5,2和3,1和3,花费17+8+10+7=42
HINT
Source
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n,x,ans:longint;
a:array[..,..] of longint;
c:array[..] of longint;
function getfat(x:longint):longint;
begin
if c[x]<>x then c[x]:=getfat(c[x]);
exit(c[x]);
end;
procedure swap(var x,y:longint);
var z:longint;
begin
z:=x;x:=y;y:=z;
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;j:=r;x:=a[(l+r) div ,];
repeat
while a[i,]>x do inc(i);
while a[j,]<x do dec(j);
if i<=j then
begin
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
swap(a[i,],a[j,]);
inc(i);dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end; {$IFDEF WINDOWS}{$R bzoj3390.rc}{$ENDIF} begin
readln(n,m);
for i:= to n do c[i]:=i;
for i:= to m do readln(a[i,],a[i,],a[i,]);
sort(,m);
j:=;x:=;
for i:= to n- do
begin
while j<=m do
begin
k:=getfat(a[j,]);
l:=getfat(a[j,]);
if k<>l then break;
inc(j);
end;
if k=l then break;
ans:=ans+a[j,];
c[k]:=l;inc(j);
inc(x);
end;
if x<(n-) then writeln(-) else writeln(ans);
readln;
end.
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复的更多相关文章
- BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
题目 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 53 Solve ...
- bzoj 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 -- 最大生成树
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MB Description 奶牛贝 ...
- 【BZOJ】3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=3390 .. #include <cstdio> #include <cstring ...
- BZOJ 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复(最大生成树)
这很明显就是最大生成树= = CODE: #include<cstdio>#include<iostream>#include<algorithm>#include ...
- bzoj 3390: [Usaco2004 Dec]Bad Cowtractors牛的报复【最大生成树】
裸的最大生成树,注意判不连通情况 #include<iostream> #include<cstdio> #include<algorithm> using nam ...
- BZOJ3390: [Usaco2004 Dec]Bad Cowtractors牛的报复
3390: [Usaco2004 Dec]Bad Cowtractors牛的报复 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 43 Solved: ...
- 【BZOJ3387】[Usaco2004 Dec]Fence Obstacle Course栅栏行动 线段树
[BZOJ3387][Usaco2004 Dec]Fence Obstacle Course栅栏行动 Description 约翰建造了N(1≤N≤50000)个栅栏来与牛同乐.第i个栅栏的z坐标为[ ...
- Bzoj 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 最短路,神题
3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 218 Solved: ...
- BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 47 Solved: 37[ ...
随机推荐
- MySQL timestamp NOT NULL插入NULL的问题
explicit_defaults_for_timestamp MySQL 5.6版本引入 explicit_defaults_for_timestamp 来控制对timestamp NULL值的处理 ...
- 大型网站制作前端使用PHP后台逻辑用 Java
对于网站团队,大概可以按照职责分为前端.后端.架构三种角色. 前端:负责所有和用户有交互的产品,包括 WEB以及手机客户端 后端:负责各种业务 API 的开发,以及服务器端其他系统的开发 架构:负责设 ...
- lufylegend库 LButton
lufylegend库 LButton <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- GreenOpenPaint的实现(一)基本框架
Win7下的MSPaint是Ribbon的典型运行.这种SDI程序对于图像处理来说是很适合的.利用春节时间,基于之前的积累,我实现GreenOpenPaint,主要就是模拟MSPaint的界面,实现出 ...
- 龙珠超的新OP【限界突破×サバイバー】
这首歌真的很燃 下载>> 限界突破×サバイバー 中文歌词 演唱:冰川清志 兴奋了!就去宇宙吧 最先端的“着迷”怎么样! 握在手中 突然想要大笑 糊里糊涂也习惯了吗! I can't g ...
- 关于hashmap的底层实现
注:以下内容并非基于最新的jdk版本 q1:hashmap为什么叫hashmap? 答:hashmap基于hashtable(不是hashtable类)实现. q2:hashtable(不是hasht ...
- Cookie与Passport安全
对于web系统而言,由于HTTP协议无状态的特性,用户登录时需要服务端生成通行证返回给浏览器.浏览器保存该通行证并在接下来的请求中携带该通行证.通常来讲,web系统使用http cookie来保存和传 ...
- ActiveMQ消息队列用法
pom.xml文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:// ...
- iOS Foundation框架 -1.常用结构体的用法和输出
1.安装Xcode工具后会自带开发中常用的框架,存放的地址路径是: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.plat ...
- lable 以及cell的高度自适应
1.先cell自适应 可以先拿到 这个lable里文字的高度 //lable自适应的高度 -(CGFloat)heightWithString:(NSString *)aString { CGRect ...