BZOJ3397: [Usaco2009 Feb]Surround the Islands 环岛篱笆
3397: [Usaco2009 Feb]Surround the Islands 环岛篱笆
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 11 Solved: 7
[Submit][Status]
Description
Input
Output
Sample Input
1 7
7 3
3 6
6 10
10 1
2 12
2 9
8 9
8 12
11 5
5 4
11 4
0 15 9 20 25 8 10 13 17 8 8 7
15 0 12 12 10 10 8 15 15 8 8 9
9 12 0 25 20 18 16 14 13 7 12 12
20 12 25 0 8 13 14 15 15 10 10 10
25 10 20 8 0 16 20 18 17 18 9 11
8 10 18 13 16 0 10 9 11 10 8 12
10 8 16 14 20 10 0 18 20 6 16 15
13 15 14 15 18 9 18 0 5 12 12 13
17 15 13 15 17 11 20 5 0 22 8 10
8 8 7 10 18 10 6 12 22 0 11 12
8 8 12 10 9 8 16 12 8 11 0 9
7 9 12 10 11 12 15 13 10 12 9 0
Sample Output
HINT
.jpg)
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 500+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,tot,fa[maxn],p[maxn],f[maxn][maxn],a[maxn];
bool v[maxn];
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)fa[i]=i;
for1(i,n)
{
int x=find(read()),y=find(read());
if(x!=y)fa[x]=y;
}
for1(i,n)
{
p[i]=find(i);
if(v[p[i]])continue;
v[p[i]]=;
a[++tot]=p[i];
}
memset(f,,sizeof(f));
for1(i,n)
for1(j,n)
f[p[i]][p[j]]=min(f[p[i]][p[j]],read());
int ans=inf;
for1(i,tot)
{
int t=;
for1(j,tot) if(i!=j)t+=f[a[i]][a[j]];
if(t<ans)ans=t;
}
printf("%d\n",ans<<);
return ;
}
BZOJ3397: [Usaco2009 Feb]Surround the Islands 环岛篱笆的更多相关文章
- bzoj:3397 [Usaco2009 Feb]Surround the Islands 环岛篱笆
Description 约翰在加勒比海买下地产,准备在这里的若干个岛屿上养奶牛.所以,他要给所有岛屿围上篱笆.每个岛屿都是多边形.他沿着岛屿的一条边界朝一个方向走,有时候坐船到另一个岛去.他可 ...
- 【BZOJ】3397: [Usaco2009 Feb]Surround the Islands 环岛篱笆(tarjan)
http://www.lydsy.com/JudgeOnline/problem.php?id=3397 显然先tarjan缩点,然后从枚举每一个scc,然后向其它岛屿连费用最小的边,然后算最小的即可 ...
- Bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 dijkstra,堆,分层图
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1573 Solv ...
- BZOJ3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 30 Solved: 17[Sub ...
- BZOJ 1579: [Usaco2009 Feb]Revamping Trails 道路升级( 最短路 )
最短路...多加一维表示更新了多少条路 -------------------------------------------------------------------------------- ...
- BZOJ 1578: [Usaco2009 Feb]Stock Market 股票市场( 背包dp )
我们假设每天买完第二天就卖掉( 不卖出也可以看作是卖出后再买入 ), 这样就是变成了一个完全背包问题了, 股票价格为体积, 第二天的股票价格 - 今天股票价格为价值.... 然后就一天一天dp... ...
- BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛( dp )
水题...忘了取模就没1A了.... --------------------------------------------------------------------------- #incl ...
- 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛
3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 243 Solved: 167[S ...
- 【BZOJ 1579】 1579: [Usaco2009 Feb]Revamping Trails 道路升级 (最短路)
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Description 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M(1<=M< ...
随机推荐
- 1000 A+B [ACM刷题]
这一段时间一直都在刷OJ,这里建一个博客合集,用以记录和分享算法学习的进程. github传送门:https://github.com/haoyuanliu/Online_Judge/tree/mas ...
- Code Snippet Library
你可以将自己常用的代码放到里面,给它命名,设置快捷键,以后想用这段代码的时候只要按快捷键,就会出现提示,直接将这段代码显示出来,十分高效. 比如我经常会用到一个动画:[UIView beginAnim ...
- poj 3182 The Grove
The Grove Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 641 Accepted: 297 Descripti ...
- [Redux] Reducer Composition with combineReducers()
Previous, we do composition with objects: const todoApp = (state = {}, action) => { return { todo ...
- unity3d android导出项目编译Multiple dex files define Lcom/unity3d/player/UnityPlayerActivity
unity3d版本: 4.1.2 在导出android工程进行编译时,发现出现Multiple dex files define Lcom/unity3d/player/UnityPlayerActi ...
- 【转】IOS7 MPMoviePlayerViewController横屏显示
在应用程序中用到MPMoviePlayerViewController时,有时需要保持应用程序为竖屏状态,而视频播放器显示为横屏,如何做呢?如果采用强制横屏的方法,应用审核的时候是不会通过的,因为该方 ...
- JAVA - Comparable接口 与 Comparator接口
Similarities:Both are custom ways to compare two objects.Both return an int describing the relatio ...
- js动态新增组合Input标签
var x = 1; function addlink() { var linkdiv = document.getElementById("add1_0"); if (linkd ...
- sql 判断表、列、视图等是否存在
1 判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名') drop database [数据库名] 2 判 ...
- Swift - 42 - 类的基本使用
import Foundation /* 1.class表示类的关键字 2.class后面表示类名 3.类名后面的大括号内表示类的内部 */ /* 1.属性封装了set和get方法 2.方法里面封装了 ...