URAL 1085 Meeting(最短路)
Meeting
Memory limit: 64 MB
friends has decided to meet in order to celebrate their victory at the
programming contest. Unfortunately, because of the tickets rise in price
there is a problem: all of them live in different parts of the city,
and they are to choose a place of meeting so that they wouldn't pay too
much for the tickets. You are to help them make the best choice.
tram routes in the city (the friends take only trams and do not go on
foot from stop to stop). For each route numbers of its stops are known.
For each friend we know an amount of money he has and whether he has a
month tram ticket. A ticket price equals 4 rubles.
are to find out a stop number, such that all of the friends might come
there and the sum of money they spend for their tramps would be minimal.
Naturally, they may change routes (it means that each one may make
changes on his way to the required stop). Note, that changing the route
one has to pay for a new ticket: the friends are honest people — they do
always pay for tickets. Everyone pays for a ticket from his own money.
No one is to leave money for the return tickets.
Input
integers defining stops numbers of the route follow. The numbers are
separated with a space. A route is defined by its stops along the line
in one direction.
The next line contains an integer K (1 ≤ K ≤ 100), that is an amount of friends. The next K
lines contain information about each of them (one line for one person):
there is a positive integer in the beginning of a line that is an
amount of money (in rubles) the person has, then a number of a stop that
he goes there from his home on foot, then 0 (if this person has no
month ticket) or 1 (if he has). The numbers in a line are separated with
a space. No one of the friends has more than 1000 rubles.
Output
a number of a stop that is a meeting
point (if there are several numbers choose the minimal one) and a total
sum of money (in rubles) that the friends has paid for their trips to
the appointed place. The numbers should be separated with a space. If
the friends won't be able to meet at one stop, output the only number 0.
Sample
input | output |
---|---|
4 3 |
4 12 |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 1e3+;
const int M = +;
const int mod=1e9+;
int n=,m,k,tot=,t;
int head[N],vis[N],in[N],sum[N];
int s[N],dis[N][N],mo[N];
vector<int>vec,vv[N];
void Floyd(){
for(int k=;k<=n;k++){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(dis[i][k]!=inf&&dis[k][j]!=inf&&dis[i][j]>dis[i][k]+dis[k][j]){
dis[i][j]=dis[i][k]+dis[k][j];
}
}
}
}return;
}
int main()
{
met(dis,inf);
for(int i=;i<N;i++)dis[i][i]=;
int u,v;
scanf("%d%d",&n,&m);
while(m--){
scanf("%d",&k);
while(k--){
scanf("%d",&u);
vec.pb(u);
}
for(int i=;i<vec.size();i++){
for(int j=i+;j<vec.size();j++){
dis[vec[i]][vec[j]]=dis[vec[j]][vec[i]]=;
}
}vec.clear();
}
Floyd();
scanf("%d",&k);
for(int i=;i<=k;i++){
scanf("%d%d%d",&mo[i],&s[i],&vis[i]);
mo[i]/=;
}
int ans=inf;
for(int i=;i<=n;i++){
int sum=;
for(int j=;j<=k;j++){
if((!vis[j]&&mo[j]<dis[i][s[j]])||dis[i][s[j]]==inf){sum=inf;break;}
if(!vis[j]&&mo[j]>=dis[i][s[j]])sum+=dis[i][s[j]];
}
if(sum==inf)continue;
if(sum<ans){
ans=sum;vv[ans].pb(i);
}
else if(sum==ans&&ans!=inf)vv[ans].pb(i);
}
if(ans!=inf){sort(vv[ans].begin(),vv[ans].end()); printf("%d %d\n",vv[ans][],ans*);}
else printf("0\n");
return ;
}
URAL 1085 Meeting(最短路)的更多相关文章
- hdu-5521 Meeting(最短路)
题目链接: Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- HDU 5521.Meeting 最短路模板题
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- 2015沈阳区域赛Meeting(最短路 + 建图)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- URAL 1072 Routing(最短路)
Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. It mea ...
- 2015沈阳站-Meeting 最短路
http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意:A,B两个人分别在1和n区.给出区之间有联系的图以及到达所需时间.求两个人见面最短时间以及在哪个 ...
- [hdu5521 Meeting]最短路
题意:有N个点,给定M个集合,集合Si里面的点两两之间的距离都为Ti,集合里面的所有点数之和<=1e6.有两个人分别在1和N处,求1个点使得两个人到这一点距离的最大值最小 思路:这题是裸的最短路 ...
- URAL题解二
URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...
- Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)
1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...
- HDU 5521 Meeting(虚拟节点+最短路)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
随机推荐
- HDU 1358 简单kmp
题目大意: 找到所有的可组成连续字符串相连的位置,和循环字符串的个数 #include <cstdio> #include <cstring> #include <alg ...
- 大学生成绩管理系统(C语言)
功能:成绩管理系统包含了学生的全部信息,每个学生是一个记录,包括学号,姓名,性别,班级,各科成绩(语数外). 系统功能: 1.信息录入——录入学生信息: 2.信息输出——显示所有信息: 3.信息查询— ...
- 支持多人协作的在线免费作图工具:ProcessOn
之前朋友给我推荐一款作图工具ProcessOn,出于好奇我就研究了一下它,今天我就给大家简单介绍一下这款免费的在线作图工具:ProcessOn 首先使用ProcessOn我们需要有一个帐号,这样每次操 ...
- Bootstrap非常简单实用的web前端开发框架
今天无意间用firebug看网站的代码发现了Bootstrap,之前从来没有听说过这个东东,于是对它产生了好奇感,通过百度我了解到了Bootstrap是一款非常简单,强悍,实用,移动设备端优先使用的这 ...
- java基础-006
37.JDBC JDBC是允许用户在不同数据库之间做选择的一个抽象层.JDBC允许开发者用JAVA写数据库引用程序,而不需要关心底层特定数据库的细节. 38.驱动(Driver) 在JDBC中的角色 ...
- 去掉NavigationBar底部的黑线
UINavigationBar *navigationBar = self.navigationController.navigationBar; [navigationBar setBackgr ...
- php大力力 [004节]PHP常量MAMP环境下加载网页
我的问题是:“让mamp加载PHP文件”. 这个特别简单的问题,刚才也把我憋了几个钟头,唉....土啊,新学一个东西,学习成本就是高. 刚刚吃了好吃的南邵小龙虾,以及美味的八里桥大螃蟹,痛苦了半天,终 ...
- Jira中Activity Stream中显示Localhost不能正常访问的处理
在“介绍”中 “你可以在系统管理页面 编辑此段文字.”将地址改为IP和端口即可
- IIS发布错误
发布程序时遇到的错误:
- mac上安装MySQL
mysql 官网下载http://dev.mysql.com/downloads/mysql/ 注意安装mysql-5.5.17-osx10.6-x86_64.dmg这样安装方便设置系统安全权限后 点 ...