bzoj 4097: [Usaco2013 dec]Vacation Planning
4097: [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.
Source
题解:
第一次接触分层图最短路。。
其实构图还是挺简单的,把图复制成两份,其中1到k的点向下连边权为0的边。
然后floyd最短路。。
#include<stdio.h>
#include<iostream>
using namespace std;
int n,m,K,Q,i,j,k,x,y,z,cnt,f[405][405];
long long ans;
int main()
{
scanf("%d%d%d%d",&n,&m,&K,&Q);
for(i=1;i<=n<<1;i++)
for(j=1;j<=n<<1;j++) f[i][j]=1e9;
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
f[x][y]=f[x+n][y+n]=z;
}
for(i=1;i<=K;i++) f[i][n+i]=0;
for(k=1;k<=n<<1;k++)
for(i=1;i<=n<<1;i++)
for(j=1;j<=n<<1;j++)
if(f[i][k]+f[k][j]<f[i][j]) f[i][j]=f[i][k]+f[k][j];
while(Q--)
{
scanf("%d%d",&x,&y);
if(f[x][y+n]!=1e9)
{
cnt++;
ans+=f[x][y+n];
}
}
cout<<cnt<<endl<<ans;
return 0;
}
bzoj 4097: [Usaco2013 dec]Vacation Planning的更多相关文章
- bzoj4097 [Usaco2013 dec]Vacation Planning
Description Air Bovinia is planning to connect the N farms (1 <= N <= 200) that the cows live ...
- [Usaco2013 DEC] Vacation Planning
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=4093 [算法] 对于k个枢纽 , 分别在正向图和反向图上跑dijkstra最短路 , ...
- bzoj 4094: [Usaco2013 Dec]Optimal Milking
4094: [Usaco2013 Dec]Optimal Milking Description Farmer John最近购买了N(1 <= N <= 40000)台挤奶机,编号为1 . ...
- 【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 3048] [Usaco2013 Jan]Cow Lineup
[bzoj 3048] [Usaco2013 Jan]Cow Lineup Description 给你一个长度为n(1<=n<=100,000)的自然数数列,其中每一个数都小于等于10亿 ...
- BZOJ 3389: [Usaco2004 Dec]Cleaning Shifts安排值班
题目 3389: [Usaco2004 Dec]Cleaning Shifts安排值班 Time Limit: 1 Sec Memory Limit: 128 MB Description ...
- BZOJ 1692: [Usaco2007 Dec]队列变换( 贪心 )
数据 n <= 30000 , 然后 O( n² ) 的贪心也过了..... USACO 数据是有多弱啊 = = ( ps : BZOJ 1640 和此题一模一样 , 双倍经验 ) ------ ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
随机推荐
- Use JPath but not recursively loop a JObject to modify the values.
I am dealing with a Json file, I parsed it into jObject, I have another list which flattened the pro ...
- Vue 使用自定义组件时报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
自己试做了一下vue的插件 参考element-ui: 写了一个组件 import message from './packages/message/index.js'; const install ...
- 面试整理(3)js事件委托
事件委托主要用于一个父容器下面有很多功能相仿的子容器,这时候就需要将子容器的事件监听交给父容器来做.父容器之所以能够帮子容器监听其原理是事件冒泡,对于子容器的点击在冒泡时会被父容器捕获到,然后用e.t ...
- 【译】第三篇 SQL Server代理警报和操作员
本篇文章是SQL Server代理系列的第三篇,详细内容请参考原文. 正如这一系列的上一篇所述,SQL Server代理作业是由一系列的作业步骤组成,每个步骤由一个独立的类型去执行,除了步骤中执行的工 ...
- KEA128单片机启动代码分析
;/*****************************************************************************; * @file: startup_SK ...
- Perl6多线程3: Promise start / in / await
创建一个Promise 并自动运行: my $p = Promise.start({say 'Hello, Promise!'}); 如果把代码改成如下, 我们会发现什么也没打印: ;say 'Hel ...
- 在字符串S1中删除字符串S2中所包含的字符【转】
转自:http://www.cnblogs.com/tolimit/p/4202959.html /************************************************** ...
- iOS 取消按钮高亮显示方法
objective-C 第1种方法: 设置按钮的normal 与 highlighted 一样的图片, 不过如果你也需要selected状态下的图片, 就不能这么做, 这样做在取消选中状态的时候就会显 ...
- /proc/cpuinfo 文件分析(查看CPU信息)
/proc/cpuinfo文件分析 根据以下内容,我们则可以很方便的知道当前系统关于CPU.CPU的核数.CPU是否启用超线程等信息. <1>查询系统具有多少个逻辑核:cat /proc/ ...
- 在rhel7上搭建centos7的yum源
1. 再查看现在主机上的yum源,并将它们删除 [root@localhost ~]# rpm -qa|grep yum | xargs rpm -e --nodeps # --nodeps 不管有没 ...