J - Invitation Cards 最短路
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 数据量太大必须用堆优化。。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define MAXN 1000010
#define INF 0x3f3f3f3f
typedef long long LL;
/*
两次 Dijkstra
结点数目太多 必须优化
*/
struct qnode
{
LL v,c;
qnode(LL _v=,LL _c=):v(_v),c(_c){}
bool operator <(const qnode &r)const
{
return c>r.c;
}
};
struct Edge
{
LL v,cost;
Edge(LL _v=,LL _cost=):v(_v),cost(_cost){}
};
struct node
{
LL f,t,d;
};
vector<Edge> E[MAXN];
node tmp[MAXN];
bool vis[MAXN];
LL dist[MAXN],n,m;
void Dijkstra(LL n,LL start)
{
memset(vis,false,sizeof(vis));
for(LL i=;i<=n;i++)
dist[i] = INF;
dist[start] = ;
priority_queue<qnode> q;
while(!q.empty()) q.pop();
q.push(qnode(start,));
qnode tmp;
while(!q.empty())
{
tmp = q.top();
q.pop();
LL u = tmp.v;
if(vis[u]) continue;
vis[u] = true;
for(LL i=;i<E[u].size();i++)
{
LL v = E[u][i].v;
LL cost = E[u][i].cost;
if(!vis[v]&&dist[v]>dist[u]+cost)
{
dist[v] = dist[u]+cost;
q.push(qnode(v,dist[v]));
}
}
}
}
void Add(LL u,LL v,LL cost)
{
E[u].push_back(Edge(v,cost));
} int main()
{
LL t;
cin>>t;
while(t--)
{
scanf("%lld%lld",&n,&m);
LL ans=;
for(LL i=;i<=n;i++) E[i].clear();
for(LL i=;i<m;i++)
{
scanf("%lld%lld%lld",&tmp[i].f,&tmp[i].t,&tmp[i].d);
Add(tmp[i].f,tmp[i].t,tmp[i].d);
}
Dijkstra(n,);
for(LL i=;i<=n;i++)
{
ans+=dist[i];
E[i].clear();
}
for(LL i=;i<m;i++)
{
Add(tmp[i].t,tmp[i].f,tmp[i].d);
}
Dijkstra(n,);
for(LL i=;i<=n;i++)
{
ans+=dist[i];
}
printf("%lld\n",ans);
}
return ;
}
J - Invitation Cards 最短路的更多相关文章
- D - Silver Cow Party J - Invitation Cards 最短路
http://poj.org/problem?id=3268 题目思路: 直接进行暴力,就是先求出举行party的地方到每一个地方的最短路,然后再求以每一个点为源点跑的最短路. 还有一种方法会快很多, ...
- poj1511/zoj2008 Invitation Cards(最短路模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Invitation Cards Time Limit: 5 Seconds ...
- HDU 1535 Invitation Cards (最短路)
题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...
- POJ1511 Invitation Cards —— 最短路spfa
题目链接:http://poj.org/problem?id=1511 Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Tota ...
- POJ-1511 Invitation Cards( 最短路,spfa )
题目链接:http://poj.org/problem?id=1511 Description In the age of television, not many people attend the ...
- hdu1535 Invitation Cards 最短路
有一张图,若干人要从不同的点到同一个中间点,再返回,求总费用最小 中间点到各个点最小费用是普通的最短路 各个点到中间点最小费用其实就是将所有路径反向建边之后中间点到各个点的最小费用,同样用最短路就可以 ...
- J - Invitation Cards
题目大意:邀请卡 在电视的时代,没有多少人会去剧院观看演出.古老的喜剧演员 Malidinesia知道这个事实.他们想传播戏剧尤其是古老的戏剧,他们在邀请卡上打印必要的信息和一些节目,一些学生被雇佣过 ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- Invitation Cards POJ - 1511 (双向单源最短路)
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
随机推荐
- mysqladmin(MySQL管理工具)
mysqladmin是一个执行管理操作的客户端程序.它可以用来检查服务器的配置和当前状态.创建和删除数据库等. 1.mysqladmin命令的语法: shell > mysqladmin [op ...
- 支持多种格式的播放器js代码
FLV需要播放器,其它视频格式直接插入相应的代码即可. ------------------------------------- /** *视频播放 by zhensheng@ *参数说明 ...
- 往文件内写入内容(java)
新建个工具类,并标记成静态的,方便调用. package util; import java.io.File;import java.io.FileOutputStream; public class ...
- Python学习笔记之默认参数
函数定义时 参数定义的顺序必须是:必选参数.默认参数.可变参数和关键字参数. def test(a,b,c=1,*d,**e) pass
- NodeJS、NPM安装配置步骤
安装NodeJS和NPM 1.Node JS 官网下载地址 https://nodejs.org/en/download/ 2.安装完后,使用cmd 命令输入两个命令,查看安装状态 node -v n ...
- Java获取一个文件夹内的所有文件(包括所有子文件夹内的)
输入文件数组.文件夹路径 返回的文件在输入的文件数组中 private void getFiles(ArrayList<File> fileList, String path) { Fil ...
- IDEA打可执行jar包
流程: 1. File ->Project Structure -> Artifacts -> + -> JAR -> From modules with depende ...
- MySQL——基本安装与使用
基本安装 下载地址:https://dev.mysql.com/downloads/mysql/ 选择解压版本:mysql-5.7.21-winx64.zip 以管理员身份打开cmd(除了安装服务不要 ...
- intellij idea console 乱码
修改文件 位置:{用户目录}\{iedea对应版本}\{idea or idea64}.vmoptions 比如我要修改我的配置文件 C:\Users\kkblf\.IntelliJIdea2017. ...
- CAD使用SetxDataLong写数据(网页版)
主要用到函数说明: MxDrawEntity::SetxDataLong 写一个long扩展数据,详细说明如下: 参数 说明 [in] BSTR val 字符串值 szAppName 扩展数据名称 n ...