Description

  In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.

  The transport system is very special: all lines are
unidirectional and connect exactly two stops. Buses leave the
originating stop with passangers each half an hour. After reaching the
destination stop they return empty to the originating stop, where they
wait until the next full half an hour, e.g. X:00 or X:30, where 'X'
denotes the hour. The fee for transport between two stops is given by
special tables and is payable on the spot. The lines are planned in such
a way, that each round trip (i.e. a journey starting and finishing at
the same stop) passes through a Central Checkpoint Stop (CCS) where each
passenger has to pass a thorough check including body scan.

  All the ACM student members leave the CCS each morning.
Each volunteer is to move to one predetermined stop to invite
passengers. There are as many volunteers as stops. At the end of the
day, all students travel back to CCS. You are to write a computer
program that helps ACM to minimize the amount of money to pay every day
for the transport of their employees.

  题目是最短路问题,求源点到所有点的来回的最短距离之和,只需要反向边图+正向边图即可。。。

代码如下:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int INF = 10e8;
const int MaxN = ; struct Edge
{
int v, cost,next;
}; Edge E1[MaxN],E2[MaxN],*E;
int head1[MaxN],head2[MaxN],Ecou1,Ecou2;
int *head;
bool vis[MaxN];
int couNode[MaxN]; bool SPFA(long long lowcost[], int n, int start,int type)
{
if(type)
E=E1,head=head1;
else
E=E2,head=head2; queue <int> que;
int u, v, c;
int len; for (int i = ; i <= n; ++i) { lowcost[i] = INF; vis[i] = ; couNode[i] = ; } vis[start] = ; lowcost[start] = ; couNode[start] = ;
que.push(start); while (!que.empty())
{
u = que.front(); que.pop(); vis[u] = ; for (int i = head[u]; i!=-; i=E[i].next)
{
v = E[i].v; c = E[i].cost; if (lowcost[v]>lowcost[u] + c)
{
lowcost[v] = lowcost[u] + c; if (!vis[v])
{
vis[v] = ; ++couNode[v]; que.push(v); if (couNode[v]>n) return ;
}
}
}
} return ;
} inline void addEdge(int u, int v, int c,int type)
{
int *Ecou;
if(type)
{
E=E1,head=head1;
Ecou=&Ecou1;
}
else
{
E=E2,head=head2;
Ecou=&Ecou2;
} E[*Ecou].v=v;
E[*Ecou].cost=c;
E[*Ecou].next=head[u];
head[u]=(*Ecou)++;
} void init(int N)
{
Ecou1=Ecou2=; for(int i=;i<=N;++i)
head1[i]=head2[i]=-;
} long long ans1[MaxN],ans2[MaxN]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T;
int N,M;
int a,b,c;
long long ans; cin>>T; while(T--)
{
scanf("%d %d",&N,&M);
init(N); for(int i=;i<=M;++i)
{
scanf("%d %d %d",&a,&b,&c);
addEdge(a,b,c,);
addEdge(b,a,c,);
} SPFA(ans1,N,,);
SPFA(ans2,N,,); ans=;
for(int i=;i<=N;++i)
ans+=ans1[i]+ans2[i]; cout<<ans<<endl;
} return ;
}

(简单) POJ 1511 Invitation Cards,SPFA。的更多相关文章

  1. POJ 1511 Invitation Cards (spfa的邻接表)

    Invitation Cards Time Limit : 16000/8000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) ...

  2. Poj 1511 Invitation Cards(spfa)

    Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...

  3. poj 1511 Invitation Cards spfa 邻接矩阵

    题目链接: http://poj.org/problem?id=1511 题目大意: 这道题目比较难理解,我读了好长时间,最后还是在队友的帮助下理解了题意,大意就是,以一为起点,求从一到其他各点的最短 ...

  4. POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)

    POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...

  5. POJ 1511 Invitation Cards(逆向思维 SPFA)

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  6. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  7. POJ 1511 Invitation Cards 链式前向星+spfa+反向建边

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 27200   Accepted: 902 ...

  8. SPFA算法(2) POJ 1511 Invitation Cards

    原题: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 31230   Accepted: ...

  9. [POJ] 1511 Invitation Cards

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 18198   Accepted: 596 ...

随机推荐

  1. TOMCAT-publishing to tomcat v7.0 server at

    因为tomcat的work文件没有清空,导致MyEclipse部署在server.xml文件中的项目路径是错误的. 解决办法:清空work文件夹 下面这个勾勾是MyEclipse自动发布项目路径的选项

  2. MyEclipse 2015 运行tomcat 内存溢出的解决方法

    内存溢出错误: 2016-3-16 11:19:55 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() ...

  3. oracle一次删除多张表

    通过拼接sql语句来完成 例如有如下个表 想一次性删除,执行如下语句: select 'drop table '||table_name ||';' as dropsql from USER_TABL ...

  4. Local declaration of 'XXX' hides instance variable

    今天调试程序遇到这么一个警告! Local declaration of 'XXX' hides instance variable 遇到这种原因,是因为本地变量跟函数参数变量同名.改变其一即可.

  5. php moungoDB

    moungoDB 语法 SQL查询语句 Mongo查询语句 CREATE TABLE USERS (a Number, b Number) 隐式的创建,或 MongoDB::createCollect ...

  6. 转:selenium 并行启动多个浏览器

    https://github.com/fool2fish/selenium-doc/blob/master/official-site/selenium-grid.md Selenium Grid 快 ...

  7. typedef void far *LPVOID 的具体定义

    首先这里的far,在32位系统已经废除不用了.它是C/C++语言在16位系统中用以标明指针是个远指针的修饰符. 远指针是说指针所指向的地址已经超出了64K(2的十六次方),所以需要使用DS加偏移量的方 ...

  8. java开发第四天——莫名其妙的一天

    搞了一天的ACM,欲哭无泪,消化的不好打了一天的嗝,然后在机房睡了一个下午,感觉还真的有点对不起队友的说.别的借口我也不找了,确实是自己不努力,时至今日,一切都是我咎由自取.等这次项目一结束我就全身心 ...

  9. h5移动端设计页面

    @京东设计中心 :去年JDC出了不少优秀的武媚娘…不,H5呢,大家都很拼,同时当然也积累了一些经验和教训,今天结合咱们的实战案例,从字体,排版,动效,音效,适配性,想法这几个方面好好聊一聊关于H5的设 ...

  10. C# 经典入门15章 -ListView 【未附代码】