D - Invitation Cards
D - Invitation Cards
Description
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.
Input
Output
Sample Input
2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50
Sample Output
46
210
//题目的意思是:第一行、一个整数N ,代表 N 个测试案例,第二行 ,两个整数 1<=P,Q<=一百万。意思是P个点,Q条 "有向边" 。然后就是Q行有向边和权值,求从点 1 到所有点的最小路径和,再加上从所有点到点 1 的最小路径和,数据保证所有点都能连通。
//牛逼的 spfa 算法,今天学习了spfa算法,很强大,bian数组是存放有向边并且成为链表的节点的,headlist的作用是建立链表,存放头节点的。d数组是存放到任一点最短路径长度的,vis不知道干嘛的,去掉也对,而且更快。。。我看到想了很久。。。作用是啥? 数据很大,0x f 用7个是错的,8个才对。然后逆序的就是将有向边反向,从 点1 走到所有点最小路径之和,好了,具体看代码吧。
71676kb 1907ms(去掉vis数组1797ms...)
#include <iostream>
#include <stdio.h>
#include <queue>
using namespace std; #define inf 0xffffffff
#define MAX 1000010 struct Bian
{
int e;
__int64 w;
int next;
}bian[][MAX];
__int64 d[MAX];
bool vis[MAX];
__int64 headlist[][MAX];
int n,m; void spfa(bool cap)
{
int i,x,y;
queue<int> Q;
for (i=;i<=n;i++)
{
d[i]=inf;
vis[i]=;
}
d[]=;
vis[]=;
Q.push();
while (!Q.empty())
{
x=Q.front();
Q.pop();
vis[x]=;
for (i=headlist[cap][x];i!=-;i=bian[cap][i].next)
{
y=bian[cap][i].e;
if (d[y]>d[x]+bian[cap][i].w)
{
d[y]=d[x]+bian[cap][i].w;
if (!vis[y])
{
vis[y]=;
Q.push(y);
}
}
}
}
} int main()
{
int N;
int a,b,i;
__int64 c;
__int64 ans;
scanf("%d",&N);
while (N--)
{
scanf("%d%d",&n,&m); for (i=;i<=n;i++) //初始化链表
{
headlist[][i]=-;
headlist[][i]=-;
} for (i=;i<=m;i++)
{
scanf("%d%d%I64d",&a,&b,&c);
bian[][i].e=b; //正序
bian[][i].w=c;
bian[][i].next=headlist[][a];
headlist[][a]=i; bian[][i].e=a; //逆序
bian[][i].w=c;
bian[][i].next=headlist[][b];
headlist[][b]=i;
}
ans=;
spfa();
for (i=;i<=n;i++)
ans+=d[i];
spfa();
for (i=;i<=n;i++)
ans+=d[i];
printf("%I64d\n",ans);
}
return ;
}
D - Invitation Cards的更多相关文章
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- HDU1535——Invitation Cards(最短路径:SPAF算法+dijkstra算法)
Invitation Cards DescriptionIn the age of television, not many people attend theater performances. A ...
- Poj 1511 Invitation Cards(spfa)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
- Invitation Cards(邻接表+逆向建图+SPFA)
Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 17538 Accepted: 5721 Description In ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- poj1511/zoj2008 Invitation Cards(最短路模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Invitation Cards Time Limit: 5 Seconds ...
- hdu 1535 Invitation Cards(SPFA)
Invitation Cards Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) T ...
- (简单) POJ 1511 Invitation Cards,SPFA。
Description In the age of television, not many people attend theater performances. Antique Comedians ...
随机推荐
- #if 条件编译
1.格式: #if constant-expression statements #elif constant-expression statements #else statements #endi ...
- 自助采样法 bootstrap 与 0.632
- 资源的GPUAddress
BufferAddress CommandHandle TextureHandle 给shader采样的 ImageHandle 给shader load store的.../imageLoad() ...
- [转载]使用expect实现shell自动交互
FROM:http://www.nginx.cn/1934.html shell脚本需要交互的地方可以使用here文档是实现,但是有些命令却需要用户手动去就交互如passwd.scp 对自动部署免去用 ...
- selenium模拟键盘操作
单键 /** * 模拟键盘回车事件 * @throws AWTException */ public void KeyEventEnter() throws AWTException { Robot ...
- 2017.7.18 linux下ELK环境搭建
参考来自:Linux日志分析ELK环境搭建 另一篇博文:2017.7.18 windows下ELK环境搭建 0 版本说明 因为ELK从5.0开始只支持jdk 1.8,但是项目中使用的是JDK 1 ...
- Android模块编译过程中的错误no rules to make target
今天花了不少时间在纠正一个编译错误: make: *** No rule to make target `out/target/common/obj/JAVA_LIBRARIES/sqlite-jdb ...
- Angular 学习笔记——ng-disable
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- iPhone手机解锁效果&&自定义滚动条&&拖拽--Clone&&窗口拖拽(改变大小/最小化/最大化/还原/关闭)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Tomcat、Weblogic、JBoss、GlassFish、Resin、Websphere弱口令及拿webshell方法总结 [复制链接]
1.java应用服务器 Java应用服务器主要为应用程序提供运行环境,为组件提供服务.Java 的应用服务器很多,从功能上分为两类:JSP 服务器和 Java EE 服务器.1.1 常见的Se ...