最短路 || POJ 1511 Invitation Cards
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define SZ 1000005
#define INF 1e18+10
long long dist[SZ], tmp[SZ], dis = ;
int head[SZ], nxt[SZ], tot = ;
int x[SZ], y[SZ];
long long z[SZ];
int use[SZ];
struct edge
{
int t;
long long d;
}l[SZ];
void build(int f, int t, long long d)
{
l[++tot] = (edge){t, d};
nxt[tot] = head[f];
head[f] = tot;
}
queue<int> q;
int p, qq;
void spfa()
{
for(int i = ; i <= p; i++) dist[i] = INF, use[i] = ;
use[] = , dist[] = ;
q.push();
while(q.size())
{
int u = q.front();
q.pop();
use[u] = ;
for(int i = head[u]; i; i = nxt[i])
{
int v = l[i].t;
if(dist[v] > dist[u] + l[i].d)
{
dist[v] = dist[u] + l[i].d;
if(!use[v])
use[v] = , q.push(v);
}
}
}
}
int main()
{
int T, s = ;
scanf("%d", &T);
while(T--)
{
scanf("%d %d", &p, &qq);
dis = ;
tot = ;
for(int i = ; i < qq; i++) head[i] = nxt[i] = use[i] = ;
for(int i = ; i < qq; i++)
{
scanf("%d %d %lld", &x[i], &y[i], &z[i]);
build(x[i], y[i], z[i]);
}
spfa();
for(int i = ; i <= p; i++) tmp[i] = dist[i];
tot = ;
for(int i = ; i < qq; i++)
head[i] = nxt[i] = use[i] = ;
for(int i = ; i < qq; i++)
build(y[i], x[i], z[i]);
spfa();
for(int i = ; i <= p; i++)
dis = dis + tmp[i] + dist[i];
printf("%lld\n", dis);
}
return ;
}
最短路 || POJ 1511 Invitation Cards的更多相关文章
- 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 / ...
- POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 16178 Accepted: 526 ...
- poj 1511 Invitation Cards(最短路中等题)
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
- poj 1511 Invitation Cards (最短路)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 33435 Accepted: 111 ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- 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 Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
随机推荐
- 让ubuntu16.04开机进入命令行模式
使用Ubuntu时,有时候我们不想开机进入桌面,想直接进入命令行,这样启动的比较快, 1.首先我们修改grub文件,改为如图所示: sudo gedit /etc/default/grub 改完之后 ...
- IT兄弟连 JavaWeb教程 URI、URL
URI介绍 URI(Uniform Resource Identifier),是统一资源标识符的缩写,是一个用于标识某一个Web资源名称的字符串,该标识允许用户对任何资源通过特定的协议进行交互.Web ...
- 第十四篇 .NET高级技术之反射
两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的生理情况.这是如何做到的呢?B超是B型超声波,它可以透过肚皮通过向你体内发射B型超声波,当超声波遇到内脏壁的时 ...
- python 导入.py
转自: https://blog.csdn.net/winycg/article/details/78512300 在同一个文件夹下调用函数:A.py文件: def add(x,y): print(' ...
- Ubuntu 18.04 LTS 安装过程
电脑: acer 1. F12开启boot menu,如果没开启,F2进去开启 2. 早点插优盘,否则进入F12的时候检测不出来,选择U盘启动,先不安装试用,进入桌面后有安装文件再安装,想直接安应该也 ...
- Mac 解登录密码Keychain
在终端输入: security unlock-keychain -p "login pwd" ~/Library/Keychains/login.keychain 在制作macOS ...
- OLE/COM Object Viewer
OLE/COM Object Viewer摘AutoIt Help The "OLE/COM Object Viewer" is a very handy tool to get ...
- 【Ajax】接收后台数据在html页面显示
Java代码 PrintWriter out=response.getWriter(); //向客户端发送字符数据 response.setContentType("text/text&qu ...
- zabbix被动模式和主动模式
1 被动模式 zabbix默认采用被动模式.就是agent等待server采集数据. 在items中,type为zabbix agent就是指被动模式. 流程为:agent周期性收集数据,server ...
- Jenkins持续集成多任务之MultiJob
项目实践中,我们可能需要在多个任务发布成功后在执行某个任务,这里就需要用到MultiJob这个插件. 案例场景:有3个任务:A.B.C,其中C任务需要等A和B执行成功后才会执行,那么就要先执行A和B, ...