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. 浅谈SQL Server 对于内存的管理

    简介 理解SQL Server对于内存的管理是对于SQL Server问题处理和性能调优的基本,本篇文章讲述SQL Server对于内存管理的内存原理. 二级存储(secondary storage) ...

  2. Viewpager实现图片轮播

    //-------------主布局文件------------------------------------- <LinearLayout xmlns:android="http: ...

  3. debug运行可以,release运行报错的原因及修改方法

    通常我们开发的程序有2种模式:Debug模式和Release模式在Debug模式下,编译器会记录很多调试信息,也可以加入很多测试代码,方便我们程序员测试,以及出现bug时的分析解决Release模式下 ...

  4. POJ 1470 Closest Common Ancestors(LCA 最近公共祖先)

    其实这是一个裸求LCA的题目,我使用的是离线的Tarjan算法,但是这个题的AC对于我来说却很坎坷……首先是RE,我立马想到数组开小了,然后扩大了数组,MLE了……接着把数组调整适当大小,又交了一发, ...

  5. 查看UDP连接情况

    运行界面,输入"CMD"命令; 在命令提示符界面中,输入"netstat -s -p udp"命令,按回车.即可显示本机所有UDP连接情况.

  6. NPOI 2.0 教程(二):编辑既存的EXCEL文件

    NPOI 2.0 教程(二):编辑既存的EXCEL文件 分类: C#技术 2014-03-11 15:40 993人阅读 评论(3) 收藏 举报 c#excelNPOI 转载请注明出处 http:// ...

  7. 团队开发里频繁使用 git rebase 来保持树的整洁好吗?

    用了以后, 树可以非常清晰, 某种程度上便于追踪, 但是 push --force 就多多了,不用呢, 合并没有远程仓库被修改的麻烦, 可是追踪又不清晰... git rebase是对commit h ...

  8. HBase集群安装

    1.HBase的机群搭建过程(在原来的hadoop0上的HBase伪分布基础上进行搭建)1.1 集群结构,主节点(hmaster)是hadoop0,从节点(region server)是hadoop1 ...

  9. SQL2005附加数据库时遇到的问题:用户组或角色在当前数据库已存在

    一次 附加备份数据库的 mdf 文件     成功后   创建登陆用户    但是  无法映射该用户的 对应数据库  出现 用户组或角色在当前数据库已存在 的问题 首先介绍一下sql server中“ ...

  10. gen_grant_dml.sql

    set echo off feedback off verify off pagesize 0 linesize 120 define v_grantee                = & ...