【题目链接】

https://www.lydsy.com/JudgeOnline/problem.php?id=1601

【算法】

最小生成树

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 310 struct Edge
{
int x,y,w;
} e[MAXN*MAXN]; int i,j,w,n,ans,tot;
int s[MAXN]; inline bool cmp(Edge a,Edge b)
{
return a.w < b.w;
}
inline int find(int x)
{
if (s[x] == x) return x;
return s[x] = find(s[x]);
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++)
{
scanf("%d",&w);
e[++tot] = (Edge){,i,w};
}
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
scanf("%d",&w);
if (i < j) e[++tot] = (Edge){i,j,w};
}
}
for (i = ; i <= n; i++) s[i] = i;
sort(e+,e+tot+,cmp);
for (i = ; i <= tot; i++)
{
if (find(e[i].x) != find(e[i].y))
{
s[find(e[i].x)] = find(e[i].y);
ans += e[i].w;
}
}
printf("%d\n",ans); return ; }

【BZOJ 1601】 灌水的更多相关文章

  1. bzoj 1601 灌水

    题目大意: 决定把水灌到n块农田,农田被数字1到n标记 把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水库 建造一个水库需要花费wi,连接两块土地需要花费Pij. 计算所需的最少代价 ...

  2. 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...

  3. BZOJ 1601 [Usaco2008 Oct]灌水

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1 ...

  4. BZOJ 1601 [Usaco2008 Oct]灌水:最小生成树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1601 题意: Farmer John已经决定把水灌到他的n(1<=n<=300 ...

  5. BZOJ——1601: [Usaco2008 Oct]灌水

    http://www.lydsy.com/JudgeOnline/problem.php?id=1601 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit:  ...

  6. BZOJ 1601 [Usaco2008 Oct]灌水 (最小生成树)

    题意 Farmer John已经决定把水灌到他的n(1<=n<=300)块农田,农田被数字1到n标记.把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水库. 建造一个水库需要 ...

  7. BZOJ 1601 USACO 2008 Oct. 灌水

    [Description] Farmer John已经决定把水灌到他的n(1<=n<=300)块农田,农田被数字1到n标记.把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水 ...

  8. BZOJ 1601: [Usaco2008 Oct]灌水 最小生成树_超级源点

    Description Farmer John已经决定把水灌到他的n(1<=n<=300)块农田,农田被数字1到n标记.把一块土地进行灌水有两种方法,从其他农田饮水,或者这块土地建造水库. ...

  9. 1601: [Usaco2008 Oct]灌水

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 1342  Solved: 881 [Submit][S ...

  10. BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...

随机推荐

  1. 关于类似vue-cli 脚手架

    #!/usr/bin/env node const download = require('download-git-repo') const program = require('commander ...

  2. Zabbix 监控磁盘IO

    Zabbix 监控磁盘IO 1.数据获取脚本 #!/bin/bash # resource: http://www.muck.net/19/getting-hard-disk-performance- ...

  3. 为什么有些异常throw出去需要在函数头用throws声明,一些就不用

    throw new IllegalStateException(".");不用在函数头声明throws IllegalStateExceptionthrow new IOExcep ...

  4. Find the build UUID in a Crash Report

    1) Find the build UUID in a Crash Report The first line in the "Binary Images:" section of ...

  5. linux强制踢出已登录的用户及本地用户

    方法一: pkill -kill -t pts/0 方法二: fuser -k /dev/pts/0 你也可以给他发送关闭信息然后关闭 echo "你被管理员踢出了" > / ...

  6. 谷歌浏览器中a:link设置字体颜色无效问题

    <div id="box"> <a href="#">111111</a> <a href=""& ...

  7. 怎么选择最适合自己的Python培训机构?

    Python培训已经成为入门Python的一个重要途径,它的优势在于学习知识的系统性.快速性和实用性.Python培训毕业的学员大多数拥有较强的实战动手能力,能够较快上手,更符合企业需求. 不过,大部 ...

  8. C解析config

    #cat bb.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include < ...

  9. 18清明校内测试T3

    扫雷(mine) Time Limit:1000ms   Memory Limit:128MB 题目描述 rsy最近沉迷于一款叫扫雷的游戏. 这个游戏是这样的.一开始网格上有n*m个位置,其中有一些位 ...

  10. TortoiseGit配置密钥的方法

    TortoiseGit 使用扩展名为ppk的密钥,而不是ssh-keygen生成的rsa密钥.使用命令ssh-keygen -C "邮箱地址" -t rsa产生的密钥在Tortoi ...