Invitation Cards
Time Limit: 8000MS   Memory Limit: 262144K
Total Submissions: 33435   Accepted: 11104

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.

Input

The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.

Output

For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.

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

题目大意:

给你一个有向图。求1到所有点和所有点到1的最短路之和。

小小变形的最短路。

所有点到1的最短路。将边都反转过来跑一遍1的单源最短路即可。证明可以自己想一下,很简单。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue> using namespace std; const int maxn=;
const long long inf=; int input[maxn+][]; int to[maxn+];
int w[maxn+];
int nex[maxn+];
int head[maxn+]; //建图
void build(int m)
{
memset(head,-,sizeof(head));
int u0,v0,w0;
for(int i=;i<m;i++)
{
u0=input[i][];
v0=input[i][];
w0=input[i][];
to[i]=v0;w[i]=w0;
nex[i]=head[u0];head[u0]=i;
}
} int vis[maxn+];
int dis[maxn+]; void spfa(int n)
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
dis[i]=inf;
queue<int> q;
q.push();
vis[]=;dis[]=;
while(!q.empty())
{
int u0=q.front();q.pop();
for(int i=head[u0];i!=-;i=nex[i])
{
int v0=to[i],w0=w[i];
if(dis[u0]+w0<dis[v0])
{
dis[v0]=dis[u0]+w0;
if(!vis[v0])
{
q.push(v0);
vis[v0]=;
}
}
}
}
} int main()
{
int nn;
scanf("%d",&nn);
while(nn--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
scanf("%d%d%d",input[i],input[i]+,input[i]+); long long ans=; build(m);
spfa(n);
for(int i=;i<=n;i++)
ans+=1LL*dis[i]; for(int i=;i<m;i++)
swap(input[i][],input[i][]);
build(m);
spfa(n);
for(int i=;i<=n;i++)
ans+=1LL*dis[i]; printf("%lld\n",ans);
}
return ;
}

poj 1511 Invitation Cards (最短路)的更多相关文章

  1. 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 / ...

  2. POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 16178   Accepted: 526 ...

  3. poj 1511 Invitation Cards(最短路中等题)

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

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

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

  5. [POJ] 1511 Invitation Cards

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

  6. DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards

    题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...

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

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

  8. Poj 1511 Invitation Cards(spfa)

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

  9. (简单) POJ 1511 Invitation Cards,SPFA。

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

随机推荐

  1. 认证域名与SSL证书的区别

    一.认证域名与SSL证书的区别 SSL 证书使访问者的 Web 浏览器和网站的服务器之间的安全. 加密连接,并确保交易的安全从篡改和拦截.认证域名向网站访客的注册和控制该网站的域名已验证.认证域名并不 ...

  2. nginx配置路径问题

    编译了一个程序放在服务器上,通过nginx配置转发访问.例如在配置下图的地址 d:\wayne\nginxWeb\www: 发现无法正常运行,查看error.log发现是有问题的,当创建文件时,ngi ...

  3. windows 10上源码编译libjpeg-turbo和使用教程 | compile and use libjpeg-turbo on windows 10

    本文首发于个人博客https://kezunlin.me/post/83828674/,欢迎阅读! compile and use libjpeg-turbo on windows 10 Series ...

  4. HTTP 协议漫谈

    转载出处:HTTP 协议漫谈 简介 网络上已经有不少介绍 HTTP 的好文章,对HTTP的一些细节介绍的比较好,所以本篇文章不会对 HTTP 的细节进行深究,而是从够高和更结构化的角度将 HTTP 协 ...

  5. 构建之法组——“别吃错喽”微信小程序评价

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9860 基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论 ...

  6. 20191010-9 alpha week 1/2 Scrum立会报告+燃尽图 07

    此作业要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/8752 一.小组情况 队名:扛把子 组长:迟俊文 组员:宋晓丽 梁梦瑶 韩昊 ...

  7. Tensorflow常用函数说明

    1.矩阵操作 1.1矩阵生成 这部分主要将如何生成矩阵,包括全0矩阵,全1矩阵,随机数矩阵,常数矩阵等 sess=tf.InteractiveSession() #x=tf.ones([2,3],tf ...

  8. Java基础面试题及答案(二)

    容器 18. java 容器都有哪些? 常用容器的图录: 19. Collection 和 Collections 有什么区别? java.util.Collection 是一个集合接口(集合类的一个 ...

  9. day20191104笔记

    MyBatis笔记: 一.MyBatis半自动ORM映射框架, 将数据库中的数据和程序中的数据进行自动映射的前提条件 1. 数据库中的字段必须和程序中的属性保持一致 2. 程序中属性的数据类型必须是基 ...

  10. vue 结合 Echarts 实现半开环形图

    Echarts 实现半开环形图 1.先看看实现的图 2.HTML部分 创建id 是 chart 的div标签. <div class="content-item"> & ...