bzoj4097 [Usaco2013 dec]Vacation Planning
Description
Input
Output
Sample Input
3 1 10
1 3 10
1 2 7
3 2
2 3
1 2
INPUT DETAILS: There are three farms (numbered 1..3); farm 1 is a hub. There is a $10 flight from farm 3 to farm 1, and so on. We wish to look for trips from farm 3 to farm 2, from 2->3, and from 1->2.
Sample Output
24
OUTPUT DETAILS: The trip from 3->2 has only one possible route, of cost 10+7. The trip from 2->3 has no valid route, since there is no flight leaving farm 2. The trip from 1->2 has only one valid route again, of cost 7.
Contest has ended. No further submissions allowed.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define inf 100000000000
using namespace std;
int n,m,k,q,tot;
long long ans;
long long dist[][];
inline LL read()
{
LL 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 main()
{
for(int i=;i<=;i++)for(int j=;j<=;j++)dist[i][j]=inf;
n=read();m=read();k=read();q=read();
for(int i=;i<=m;i++)
{
int x=read(),y=read();
dist[x][y]=dist[x+n][y+n]=read();
}
for(int i=;i<=k;i++)dist[i][n+i]=;
for(int l=;l<=*n;l++)
for (int i=;i<=*n;i++)
for (int j=;j<=*n;j++)
if (dist[i][j]>dist[i][l]+dist[l][j])
dist[i][j]=dist[i][l]+dist[l][j];
for (int i=;i<=q;i++)
{
int x=read(),y=read();
if (dist[x][n+y]>1e10)continue;
tot++;ans+=dist[x][n+y];
}
printf("%d\n%lld",tot,ans);
}
bzoj4097
bzoj4097 [Usaco2013 dec]Vacation Planning的更多相关文章
- bzoj 4097: [Usaco2013 dec]Vacation Planning
4097: [Usaco2013 dec]Vacation Planning Description Air Bovinia is planning to connect the N farms (1 ...
- [Usaco2013 DEC] Vacation Planning
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4093 [算法] 对于k个枢纽 , 分别在正向图和反向图上跑dijkstra最短路 , ...
- 【Floyd(并非水题orz)】BZOJ4093-[Usaco2013 Dec]Vacation Planning
最近刷水太多标注一下防止它淹没在silver的水题中……我成为了本题,第一个T掉的人QAQ [题目大意] Bovinia设计了连接N (1 < = N < = 20,000)个农场的航班. ...
- 【BZOJ4094】[Usaco2013 Dec]Optimal Milking 线段树
[BZOJ4094][Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号 ...
- bzoj 4094: [Usaco2013 Dec]Optimal Milking
4094: [Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号为1 . ...
- bzoj4096 [Usaco2013 dec]Milk Scheduling
Description Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which ta ...
- [USACO 13DEC]Vacation Planning(gold)
Description Air Bovinia operates flights connecting the N farms that the cows live on (1 <= N < ...
- [USACO13DEC]假期计划(黄金)Vacation Planning (gold)
题目翻译不好,这里给出一份 题目背景 Awson是某国际学校信竞组的一只大佬.由于他太大佬了,于是干脆放弃了考前最后的集训,开车(他可是老司机)去度假.离开学校前,他打开地图,打算做些规划. 题目描述 ...
- BZOJ4095 : [Usaco2013 Dec]The Bessie Shuffle
首先将排列和整个序列以及询问都反过来,问题变成给定一个位置$x$,问它经过若干轮置换后会到达哪个位置. 每次置换之后窗口都会往右滑动一个,因此其实真实置换是$p[i]-1$. 对于每个询问,求出轮数, ...
随机推荐
- Python之路,Day22 - 网站用户访问质量分析监测分析项目开发
Python之路,Day22 - 网站用户访问质量分析监测分析项目开发 做此项目前请先阅读 http://3060674.blog.51cto.com/3050674/1439129 项目实战之 ...
- net 关于系统性能调优了解和看法
系统性能调优这是每个大中型项目的必要手段,当系统运行积累到一定量的时候 这个时候就需要一个质变的过程那这个时候就少不了优化和调整 (前几天看了一篇文章 感觉写的挺好,也挺实在的 链接:http:// ...
- asp.net 真正实现完全跨域单点登录
单点登录(Single Sign On),简称为 SSO,是目前比较流行的企业业务整合的解决方案之一.SSO的定义是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统. asp.ne ...
- 判断iPhone和iPad 判断设备版本
//判断iPhone和iPad #define IS_IPHONE (!IS_IPAD) #define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInt ...
- 测试stopwatch频率
测试stopwatch频率 using UnityEngine; using System.Collections; using System.Diagnostics; public class te ...
- android 9Path图片的使用
Android UI设计时,经常会使用图片作为背景,比如给按钮设置背景图片时,图片会默认缩放来适应整个按钮.但是有时这种缩放效果并不是我们所需求的.而我们只是希望缩放图片的特定位置,以此来保证按钮的视 ...
- 可以让PHP编程事半功倍的类库
在用php开发网站的时候,使用面向对象的方法确实可以提高代码复用率,减少代码冗余.而对初学者更友好的是,PHP开发网站所需要的大部分类库,网上都有十分优秀的类库存在了.作为一个程序猿当然不能重复制造轮 ...
- C++ Primer 5th 第11章 关联容器
练习11.1:描述map 和 vector 的不同. map是关联容器,vector是顺序容器,关联容器与值无关,vector则与值密切相关 练习11.2:分别给出最适合使用 list.vector. ...
- js 得到当前季度
Date.prototype.getQuarter = function() { var month = this.getMonth(); if(month < 3) { return '第一季 ...
- PHP图的绘制1
最近在学习php图的绘制,写的代码放上来,供自己以后学习查看: <?php //*函数说明: //这个函数返回的是 // resource imagecreate ( int $x_size , ...