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$. 对于每个询问,求出轮数, ...
随机推荐
- C#解leetcode 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- python文档字符串
#coding=utf-8 #文档字符串def d(i,j): """这个函数实现了一个乘法运算. 函数会返回一个乘法运算的结果.""" k ...
- 学习CSS一些事(下)
2.浮动(float) 浮动(float)特点:1.元素会左移.右移,直到触碰到容器为止. 2.设置浮动元素,仍旧处于标准文档流. 3.当元素没有设置宽度值,而设置了浮动属性,元素的宽度随着内容 ...
- Linq101-Miscellaneous
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Miscell ...
- show_space.sql.txt
create or replace procedure SHOW_SPACE(P_SEGNAME IN VARCHAR2, P_OWNER IN VARCHAR2 DEFAULT USER ...
- Sql Xtype
SQL Server xtype的介绍 在数据库内创建的每个对象(约束.默认值.日志.规则.存储过程等)在表中占一行.只有在 tempdb 内,每个临时对象才在该表中占一行. 列名 数据类型 描 ...
- javascript基础学习(十二)
javascript之BOM 学习要点: 屏幕对象 History对象 Location对象 一.屏幕对象 Screen对象是一个由javascript自动创建的对象,该对象的主要作用是描述客户端的显 ...
- UNIX基础知识
一.线程 线程是进程某程序段的一次运行. 1.线程共享资源,利用共享的资源,线程很容易能够互相通信 (1)进程代码段:每个线程有各自的寄存器组,在运行时期拷贝给cpu寄存器,来确定运行的是哪段代码段. ...
- ActiveReports 交互式报表之向下钻取解决方案
在 ActiveReports 中可以动态的显示或者隐藏某区域的数据,通过该功能用户可以根据需要显示或者隐藏所关心的数据,结合数据排序.过滤等功能可以让用户更方便地分析报表数据. 本文中展示的是销售数 ...
- JavaScript作用域链详解
JavaScript的作用域链还是很有味道的,搞懂了这个知识点,闭包的问题也就迎刃而解咯 1.JavaScript的全局变量和局部变量 首先,先来看看js的全局变量和局部变量,js不是块级作用域,所以 ...