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. http的状态码(中英文)

    1**:请求收到,继续处理 2**:操作成功收到,分析.接受 3**:完成此请求必须进一步处理 4**:请求包含一个错误语法或不能完成 5**:服务器执行一个完全有效请求失败 100——客户必须继续发 ...

  2. ALAssetsLibrary 照片相关 浅析

    ALAssetsLibrary 提供了访问iOS设备下”照片”应用下所有照片和视频的接口: 从 ALAssetsLibrary 中可读取所有的相册数据,即 ALAssetsGroup 对象列表: 从每 ...

  3. python 对比图片相似度

    最近appium的使用越来越广泛了,对于测试本身而言,断言同样是很重要的,没有准确的断言那么就根本就不能称之为完整的测试了.那么目前先从最简单的截图对比来看.我这里分享下python的图片相似度的代码 ...

  4. 文字在边界自动换行word-wrap:break-word

    div容器内中内容将在边界内换行,(word-wrap)英语句子中单词内不强制换行.(word-break)如果需要词内换行

  5. HDU1518:Square(DFS)

    Square Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  6. 每个程序员都应该学习使用Python或Ruby

    每个程序员都应该学习使用Python或Ruby 如果你是个学生,你应该会C,C++和Java.还会一些VB,或C#/.NET.多少你还可能开发过一些Web网页,你知道一些HTML,CSS和JavaSc ...

  7. android5.0----SVG

    SVG ----scalable vector Graphics 可缩放矢量图形 android L 即android 5.0的新特性. 1,SVG是干什么的? 可缩放矢量图形是基于可扩展标记语言(标 ...

  8. int *p[4]与int (*q)[4]的区别

    以上定义涉及两个运算符:“*”(间接引用).“[]”(下标),“[]”的优先级别大于“*”的优先级别. 首先看int *p[4],“[]”的优先级别高,所以它首先是个大小为4的数组,即p[4]:剩下的 ...

  9. hdu_5724_Chess(组合博弈)

    题目链接:hdu_5724_Chess 题意: 给你一个n行20列的棋盘,棋盘里面有些棋子,每个棋子每次只能往右走一步,如果右边有棋子,可以跳过去,前提是最右边有格子,如果当前选手走到没有棋子可以走了 ...

  10. Android消息提示框Toast

    Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...