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 ...
随机推荐
- Python os.path.dirname(__file__) os.path.join(str,str)
Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__f ...
- VueJS 轻松支持 JSX 配置
使用: babel-preset-vue-app TODO
- VueJS ElementUI el-table 的 formatter 和 scope template 不能同时存在
暂时可以通过 在 scope template 中自己处理格式化解决 相关issue: 2548
- Supply
Supplier创建一个Supply Supply有tap或emit方法. 可以这样理解: Supplier创建一个工厂 Supply 用tap创建流水线 emit向流水线上传送加工品进行加厂 my ...
- perl6 Socket
Perl6 中的SOCKET就是相当于Perl5 的 IO::Socket::INET. 官方介绍如下: #下面是客户端multi method new( :$host, :$port, :, :$e ...
- 14 - 函数参数检测-inspect模块
目录 1 python类型注解 2 函数定义的弊端 3 函数文档 4 函数注解 4.1 annotation属性 5 inspect模块 5.1 常用方法 5.2 signature类 5.3 par ...
- centos如何设置定时任务
1.crontab -e 打开任务列表,输入i开始编写面之后按esc退出编写默写,:wq保存退出即可. 2.关于时间格式的定义,,请使用下面的网站 https://crontab.guru/#00_0 ...
- 190.Reverse Bits---位运算
题目链接:https://leetcode.com/problems/reverse-bits/description/ 题目大意:将数值的二进制反转. 法一(借鉴):由于是无符号32位整型,当二进制 ...
- 使用extjs做的一个简单grid
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...
- CGIC简明教程(转摘)
CGIC简明教程 本系列的目的是演示如何使用C语言的CGI库“CGIC”完成Web开发的各种要求. ********************************* 基础知识 1 ...