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$. 对于每个询问,求出轮数, ...
随机推荐
- Unity3d Awake、OnEnable、Start生命周期
Unity3d,Awake.OnEnable.Start,都是游戏开始运行前,所运行的方法. GameObject的Activity为true,脚本的enable为true时,其先后顺序为:Awake ...
- Swift的闭包(二):捕获值
闭包可以从定义它的上下文中捕获常量和变量. 在Swift中,捕获值最简单的例子是嵌套函数,举个例子: func makeIncrementer(forIncrement amount: Int) -& ...
- Linux后台开发面试问题汇总
个人从事安全后台开发,当然是linux环境下的了.举几个常见的问题.1. 数据结构基础.比如实现一个最简单的哈希表.2. 操作系统基础.linux进程模型,堆/栈的区别,大概的位置,各往哪个方向生长, ...
- Java基础知识强化19:Java中switch分支语句
java中switch语句: 这里expression控制表达式的数据类型只能是byte.short.char.int四种整型类型和枚举类型,不能是boolean类型: Java7(1.7)改进了sw ...
- 新一代 PHP 加速插件 Zend Opcache <转>
注: 由于原链接已不存在, 所以我把图片重新整理了一下, 以便看起来更加直观 笔者注: 1> PHP 性能提升之 PHP NG => php next generation wiki ...
- python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数
练习一:打出1-100之间的所有偶数 def even_print(): for i in range(1,101): if i % 2 == 0: print (i) even_print() #列 ...
- python摇骰子猜大小的小游戏
#小游戏,摇筛子押大小的小游戏玩家初始有1000块钱,可以压大压小作为赌注 import random #定义摇筛子的函数: def roll_dice(number = 3,points = Non ...
- 教你写Jquery插件
最近很多网友说 jQuery插件是什么啊?怎么写的啊?我不会写啊? 一大堆的问题一时都不知道怎么回答他们,个人认为是网友们把问题复杂化了. 其实就是把一些常用.实用.通用的功能封装起来而以,简单的来讲 ...
- Razor html标签
1.Label Html语法: <label for=“UserName”>用户名</label> Razor语法: @Html.LabelFor(m=>m.UserNa ...
- Excel 2007中的新文件格式
*.xlsx:基于XML文件格式的Excel 2007工作簿缺省格式 *.xlsm:基于XML且启用宏的Excel 2007工作簿 *.xltx:Excel2007模板格式 *.xltm:Excel ...