Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)
题目描述
airline and he’s received a voucher for one free flight between any two destinations he wishes.
He is already planning next year’s trip. He plans to travel by car where necessary, but he may be using his free flight ticket for one leg of the trip. He asked for your help in his planning.
He can provide you a network of cities connected by roads, the amount it costs to buy gas for traveling between pairs of cities, and a list of available flights between some of those cities. Help Peter by finding the minimum amount of money he needs to spend to get from his hometown to next year’s destination!
输入
The first line is followed by m lines, each describing one road. A road description contains three space-separated integers i, j, and c (0 ≤ i, j < n, i 6= j and 0 < c ≤ 50 000), indicating there is a road connecting cities i and j that costs c cents to travel. Roads can be used in either direction for the same cost. All road descriptions are unique.
Each of the following f lines contains a description of an available flight, which consists of two space-separated integers u and v (0 ≤ u, v < n, u 6= v) denoting that a flight from city u to city v is available (though not from v to u unless listed elsewhere). All flight descriptions are unique.
输出
样例输入
8 11 1 0 5
0 1 10
0 2 10
1 2 10
2 6 40
6 7 10
5 6 10
3 5 15
3 6 40
3 4 20
1 4 20
1 3 20
4 7
样例输出
45 题意:n个点,m条双向边,f条单向边,单向边只能用一条,且费用为0,从s到t的最短路。
思路:分层建图,两个图之间用费用为0的单向边连接,跑dijstra
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
const int maxn = ;
const int ad=5e5+;
typedef pair<ll,int>pli;
struct Node
{
int y,val,next;
Node(int y=,int val=,int next=):y(y),val(val),next(next) {}
} node[maxn<<]; int head[ad<<];
int cnt;
int n,m,f,s,t;
void add1(int x,int y,int val)
{
node[++cnt].y=y;
node[cnt].val=val;
node[cnt].next=head[x];
head[x]=cnt;
node[++cnt].y=y+ad;
node[cnt].val=val;
node[cnt].next=head[x+ad];
head[x+ad]=cnt;
} void add2(int x,int y)
{
node[++cnt].y=y+ad;
node[cnt].val=;
node[cnt].next=head[x];
head[x]=cnt;
}
priority_queue<pli,vector<pli>,greater<pli> >que;
bool vis[ad<<];
ll dist[ad<<];
void dijstra()
{
while(!que.empty())
que.pop();
memset(dist,0x3f,sizeof(dist));
memset(vis,,sizeof(vis));
que.push(pli(,s));
while(!que.empty())
{
pli tmp = que.top();
que.pop();
int k = tmp.second;
ll v = tmp.first;
if(vis[k])
continue;
vis[k]=;
dist[k]=v;
for(int i=head[k]; i; i=node[i].next)
{
int to=node[i].y;
if(dist[to] > v+node[i].val)
{
que.push(pli(v+node[i].val,to));
}
}
}
}
int main()
{
scanf("%d%d%d%d%d",&n,&m,&f,&s,&t);
cnt = ;
memset(head,,sizeof(head));
for(int i=; i<=m; i++)
{
int u,v,k;
scanf("%d%d%d",&u,&v,&k);
add1(u,v,k);
add1(v,u,k);
}
for(int i=; i<=f; i++)
{
int u,v;
scanf("%d%d",&u,&v);
add2(u,v);
}
dijstra();
printf("%lld\n",min(dist[t],dist[ad+t]));
}
Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)的更多相关文章
- ICPC North Central NA Contest 2018
目录 ICPC North Central NA Contest 2018 1. 题目分析 2. 题解 A.Pokegene B.Maximum Subarrays C.Rational Ratio ...
- 【BZOJ-1570】BlueMary的旅行 分层建图 + 最大流
1570: [JSOI2008]Blue Mary的旅行 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 388 Solved: 212[Submit ...
- 2019 ACM/ICPC North America Qualifier G.Research Productivity Index(概率期望dp)
https://open.kattis.com/problems/researchproductivityindex 这道题是考场上没写出来的一道题,今年看看感觉简单到不像话,当时自己对于dp没有什么 ...
- The North American Invitational Programming Contest 2017 题目
NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black st ...
- The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...
- The North American Invitational Programming Contest 2018 H. Recovery
Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
随机推荐
- Tomcat系列(4)——Tomcat 组件及架构详细部分
核心部分 1. 定义 Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta ...
- SSH 连接慢
关闭连接时的 DNS 解析 # 编辑配置文件,修改如下配置项 vim /etc/ssh/sshd_config GSSAPIAuthentication no UseDNS no # 重启服务 sys ...
- DirectX11 With Windows SDK--24 Render-To-Texture(RTT)技术的应用
前言 尽管在上一章的动态天空盒中用到了Render-To-Texture技术,但那是针对纹理立方体的特化实现.考虑到该技术的应用层面非常广,在这里抽出独立的一章专门来讲有关它的通用实现以及各种应用. ...
- Python高级笔记(二) -- 深拷贝和浅拷贝
1. 深拷贝 1.1 类型1 注意: d没有改变, 因为d所拷贝的数据没有改变, 而是c往后添加数据. 1.2 类型2: 元组 如果copy.copy拷贝的是元组是深拷贝! 不会进行浅拷贝, 仅仅是指 ...
- sql 查询某个条件多条数据中最新的一条数据或最老的一条数据
sql 查询某个条件下多条数据中最新的一条数据或最老的一条数据 test_user表结构如下: 需求:查询李四.王五.李二创建的最初时间或者最新时间 1:查询最初的创建时间: SELECT * FRO ...
- torchvision 作用
1. 提供主流的model,和常用数据集 2. 对 torch.utils.data.Dataset进行扩充,针对不同类别图像放入不同文件夹的数据进行读取, torchvision.datasets. ...
- HTTP常见的状态码——面试题常考
一些常见的状态码为: 200 - 服务器成功返回网页 400(错误请求)服务器不理解请求的语法. 404 - 请求的网页不存在 500(服务器内部错误)服务器遇到错误,无法完成请求. 503 - 服 ...
- js关联数组
标准javascript 是内含支持hash关联数组,经查找资料并测试,有关标准javascript内含的hash关联数组操作备忘如下 1.Hash关联数组定义 // 定义空数组 myhash = { ...
- Selenium for C#(一) 环境安装
Selenium 环境安装 本地环境为VS2015,由于selenium 官网不知什么原因打不开. 特记录下VS上使用NuGet安装Selenium的步骤. 利用Package Manager Con ...
- Debian 无线网络切换问题解决方案
sudo gedit /etc/NetworkManager/NetworkManager.conf 2: 添加 [device] wifi.scan-rand-mac-address=no 3:重启 ...