Meeting

Time limit: 2.0 second
Memory limit: 64 MB
K
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.
All stops are enumerated with integers 1, …, N inclusive. There are M
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.
You
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

The first line contains two integers N and M; 1 ≤ N, M ≤ 100 (N is a number of stops, M is a number of routes). The next M lines define the routes in the following sort: there is an integer L in the beginning of a line — that is an amount of stops of the corresponding route (2 ≤ L ≤ 100). Then L
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

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
  1. 4 3
  2. 2 1 2
  3. 2 2 3
  4. 2 3 4
  5. 3
  6. 27 1 0
  7. 15 4 0
  8. 45 4 0
  1. 4 12
Problem Author: Alexander Somov
【题意】一个城市中有很多公交站,每条公交路线链接一些公交站(双向),每辆公交车车票为4卢布。有那么一群朋友住在其中的一些车站,他们想选择一个公交站聚会,使得每个人都能靠自己的钱到达聚会地点,且总花费最短。现给定所有人的钱,出发地点,是否具有月票(有月票的不需要花钱),求聚会地点(若有多个满足条件,输出编号最小的)和总花费。
【分析】考虑到一条公交路线上的点只需要花一张车票,所以将一条公交路线上的点的距离都赋值1,然后Floyd求出任意两点最短路,然后枚举答案。
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <string>
  7. #include <map>
  8. #include <stack>
  9. #include <queue>
  10. #include <vector>
  11. #define inf 0x3f3f3f3f
  12. #define met(a,b) memset(a,b,sizeof a)
  13. #define pb push_back
  14. typedef long long ll;
  15. using namespace std;
  16. const int N = 1e3+;
  17. const int M = +;
  18. const int mod=1e9+;
  19. int n=,m,k,tot=,t;
  20. int head[N],vis[N],in[N],sum[N];
  21. int s[N],dis[N][N],mo[N];
  22. vector<int>vec,vv[N];
  23. void Floyd(){
  24. for(int k=;k<=n;k++){
  25. for(int i=;i<=n;i++){
  26. for(int j=;j<=n;j++){
  27. if(dis[i][k]!=inf&&dis[k][j]!=inf&&dis[i][j]>dis[i][k]+dis[k][j]){
  28. dis[i][j]=dis[i][k]+dis[k][j];
  29. }
  30. }
  31. }
  32. }return;
  33. }
  34. int main()
  35. {
  36. met(dis,inf);
  37. for(int i=;i<N;i++)dis[i][i]=;
  38. int u,v;
  39. scanf("%d%d",&n,&m);
  40. while(m--){
  41. scanf("%d",&k);
  42. while(k--){
  43. scanf("%d",&u);
  44. vec.pb(u);
  45. }
  46. for(int i=;i<vec.size();i++){
  47. for(int j=i+;j<vec.size();j++){
  48. dis[vec[i]][vec[j]]=dis[vec[j]][vec[i]]=;
  49. }
  50. }vec.clear();
  51. }
  52. Floyd();
  53. scanf("%d",&k);
  54. for(int i=;i<=k;i++){
  55. scanf("%d%d%d",&mo[i],&s[i],&vis[i]);
  56. mo[i]/=;
  57. }
  58. int ans=inf;
  59. for(int i=;i<=n;i++){
  60. int sum=;
  61. for(int j=;j<=k;j++){
  62. if((!vis[j]&&mo[j]<dis[i][s[j]])||dis[i][s[j]]==inf){sum=inf;break;}
  63. if(!vis[j]&&mo[j]>=dis[i][s[j]])sum+=dis[i][s[j]];
  64. }
  65. if(sum==inf)continue;
  66. if(sum<ans){
  67. ans=sum;vv[ans].pb(i);
  68. }
  69. else if(sum==ans&&ans!=inf)vv[ans].pb(i);
  70. }
  71. if(ans!=inf){sort(vv[ans].begin(),vv[ans].end()); printf("%d %d\n",vv[ans][],ans*);}
  72. else printf("0\n");
  73. return ;
  74. }

URAL 1085 Meeting(最短路)的更多相关文章

  1. hdu-5521 Meeting(最短路)

    题目链接: Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  2. HDU 5521.Meeting 最短路模板题

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  3. 2015沈阳区域赛Meeting(最短路 + 建图)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. URAL 1072 Routing(最短路)

    Routing Time limit: 1.0 secondMemory limit: 64 MB There is a TCP/IP net of several computers. It mea ...

  5. 2015沈阳站-Meeting 最短路

    http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意:A,B两个人分别在1和n区.给出区之间有联系的图以及到达所需时间.求两个人见面最短时间以及在哪个 ...

  6. [hdu5521 Meeting]最短路

    题意:有N个点,给定M个集合,集合Si里面的点两两之间的距离都为Ti,集合里面的所有点数之和<=1e6.有两个人分别在1和N处,求1个点使得两个人到这一点距离的最大值最小 思路:这题是裸的最短路 ...

  7. URAL题解二

    URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...

  8. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

  9. HDU 5521 Meeting(虚拟节点+最短路)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

随机推荐

  1. vim的编码设置

    VIM的相关字符编码主要有三个参数 fencs: 它是一个编码格式的猜测列表.当用vim打开某个文件时,会依次取这里面的编码进行解码,如果某个编码格式从头至尾解码正确,那么就用那个编码 fenc:它是 ...

  2. C++中两块内存重叠的string的copy方法

    如果两段内存重叠,用memcpy函数可能会导致行为未定义. 而memmove函数能够避免这种问题,下面是一种实现方式: #include <iostream> using namespac ...

  3. monkey(1)

    写完应用之后,作完单元测试和功能测试,必要对应用的抗打击能力做个测试,最好的方法是雇个“猴子”在测试,猴子可以胡乱瞎按键,在这种情况下,你的应用是否还能正常工作呢?Android 测试包中提供了一个M ...

  4. JVM-class文件完全解析-方法表集合

    方法表集合 前面的魔数,次版本号,主板本号,常量池入口,常量池,访问标志,类索引,父类索引,接口索引集合,字段表集合,那么再接下来就是方法表了.   方法表的构造如同字段表一样,依次包括了访问标志(a ...

  5. scanf

    scanf函数: (1)与printf函数一样,都被定义在头文件stdio.h里,因此在使用scanf函数时要加上#include <stdio.h>.它是格式输入函数,即按用户指定的格式 ...

  6. 国内android帮助文档镜像网站---http://wear.techbrood.com/develop/index.html

    http://wear.techbrood.com/develop/index.html

  7. PAT 07-2 A+B和C

    有两个值得注意的地方:1.变长数组(VLA)的使用,没想到PAT上的OJ竟然支持C99,一开始不知道就没用,看了看别人的,既然,还是用吧, 它有一点我不太喜欢,它不能像一般数组那样在声明时通过赋一个0 ...

  8. Ogre中TerrainSceneManager

    转自:http://blog.csdn.net/yanonsoftware/article/details/1103665 TerrainSceneManager是一个OctreeSceneManag ...

  9. Note_Master-Detail Application(iOS template)_07_ YJYDetailViewController.m

    //  YJYDetailViewController.m #import "YJYDetailViewController.h" @interfaceYJYDetailViewC ...

  10. php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊??????

    php大力力 [028节] 如何下载js文件,网上一个*.js无法下载啊?????? safari也无法下载 迅雷也无法下载 是不是对方网站服务器的不让下载那个js目录的文件??? 只能调用js函数啊 ...