最短路 || 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 ... 
随机推荐
- centos7 编译安装新版LNMP环境
			centos7 编译安装新版LNMP环境 环境版本如下: 1.系统环境:Centos 7 x86_64 2.NGINX:nginx-1.11.3.tar.gz 3.数据库:mariadb-10.0.2 ... 
- UVa 1642 Magical GCD (暴力+数论)
			题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ... 
- DFS系列 POJ(自认为的讲解)
			C - Sum It Up POJ1564 题意: 给你一个N,然后给你一堆数The numbers in each list appear in nonincreasing order, and t ... 
- hdoj1260【简单DP】
			这题就是一个人买还是两个人买,直接选择一下,而且默认是排好了的,就是DP一下,可能不知道DP的人,也是这么写的吧.DP是一种思想啊. #include <bits/stdc++.h> us ... 
- PTA 模拟【string以及字母->数组下标】
			假设有九宫格输入法键盘布局如下: [ 1,.?! ] [ 2ABC ] [ 3DEF ] [ 4GHI ] [ 5JKL ] [ 6MNO ] [ 7PQRS ] [ 8TUV ] [ 9WXYZ ] ... 
- TFS 用户设置read权限后仍然无法查看代码的问题
			TFS 2013 在visual studio , team explorer , source control explorer 中点击 文件夹 右键菜单 Security 打开一个winform( ... 
- 鸟哥私房菜基础篇:安裝 CentOS7.x习题
			猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0157installcentos7.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-Linux的目 ... 
- 左耳朵耗子:我为什么要在极客时间 App 开设独家专栏?
			参考链接:https://www.infoq.cn/article/2018/01/why-geektime 不少朋友都知道我在极客时间App 上开了一个收费专栏<左耳听风>,这个专栏会开 ... 
- Luogu P1417烹调方案【dp/背包】By cellur925
			题目传送门 我们看到这道题,就会想起背包.于是我就一顿01背包敲,结果发现只有30分.后来看题解发现需要对输入的食材进行排序. 我们回想国王游戏一题,各位大臣的排列顺序会对权值造成影响,所以我们就预先 ... 
- Jquery | 基础 | 慕课网 | 类选择器
			原生getElementsByClassName()函数的实现代码与jQuery实现代码的比较: <!DOCTYPE html> <html> <head> < ... 
