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. SDWebImage的总结

    SDWebImage 1> 图片文件缓存的时间有多长:1周 _maxCacheAge = kDefaultCacheMaxCacheAge 2> SDWebImage 的内存缓存是用什么实 ...

  2. Bill Total Value

    Bill Total Value time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. hiho#1128 : 二分·二分查找

    input 1<=n<=1e6 1<=k<=2*1e9 a1 a2 ... an 1<=an<=2*1e9 output k存在则输出k是第几大的数,否则输出-1 ...

  4. less分页阅读

    less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...

  5. ExtJS4 的dom

    Ext使用了三个核心的工具类对我们掌握的DOM进行了完美的封装. ┣ Ext.Element(几乎对DOM的一切进行了封彻底装) ┣ Ext.DomHelper(一个强大的操控UI界面的工具类) ┣ ...

  6. Apache无法启动提示the requested operation has failed

    主要参考这篇 http://apps.hi.baidu.com/share/detail/15868128 但还是遇到一些问题,记录如下: 1. 配置完成后,restart apache,出现 the ...

  7. dubbo Forbid blacklist

    http://www.jameswxx.com/dubbo/%E8%A7%A3%E5%86%B3dubbo%E9%97%AE%E9%A2%98%EF%BC%9Aforbid-consumer/

  8. 关于window.location.href="delete_emp.do?id"+id;

    ?后面是参数 ?id 就是带参发送这个请求 参数就是id  后面的 +id 貌似 是值

  9. java代码如何发送QQ邮件

    近来想写一个qq之间互相发送邮件的工具.奈何一直报错服务错误: org.apache.commons.mail.EmailException: Sending the email to the fol ...

  10. Barnicle

    Barnicle Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his h ...