两次SPFA。

求 来 和 回 的最短路之和。

用Dijkstra+邻接矩阵确实好写+方便交换。可是这个有1000000个点。矩阵开不了。

d1[]为 1~N 的最短路。

将全部边的 邻点 交换。

d2[] 为 1~N 的最短路。

全部相加为 所要答案。

忧伤的是用SPFA  “HDU 1535”  AC了。可是POJ 一样的题 “POJ 1511” 就WA了。

然后强迫症犯了。不停的去測试。

题意中找到一句关键话 :Prices are positive integers the sum of which is smaller than 1000000000

本来int 能够的。HDU 就是这样。

然后我就把POJ的求和 改成了 long long 。

还是WA。

然后发现 我的INF 有问题。0xfffffff 不够。然后改成0x7fffffff int的最大值。AC了。

POJ 数据也真是屌。

全然不看题意的。

#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
using namespace std;
int n,m;
struct lx
{
int v,d;
};
int dis[1000001];
bool vis[1000001];
int e[1000001];
vector<lx>g[1000001];
void swapg()
{
for(int i=1;i<=n;i++)
e[i]=g[i].size();
for(int i=1;i<=n;i++)
{
int u,v,d;
lx now;
u=i;
for(int j=0;j<e[i];j++)
{
v=g[u][j].v,d=g[u][j].d;
now.d=d,now.v=u;
g[v].push_back(now);
}
}
}
int SPFA(int thend) // long long
{
for(int i=1;i<=n;i++)
dis[i]=INF,vis[i]=0;
queue<int>q;
dis[1]=0,vis[1]=1;
q.push(1);
while(!q.empty())
{
int u=q.front();q.pop();
vis[u]=0;
for(int j=e[u];j<g[u].size();j++)
{
int v=g[u][j].v;
int d=g[u][j].d;
if(dis[v]>dis[u]+d)
{
dis[v]=dis[u]+d;
if(!vis[v])
{
vis[v]=1;
q.push(v);
}
}
}
}
int ans=0; //long long
for(int i=1;i<=n;i++)
ans+=dis[i];
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int u,v,d;
lx now;
for(int i=1;i<=n;i++)
g[i].clear();
while(m--)
{
scanf("%d%d%d",&u,&v,&d);
now.d=d;
now.v=v;
g[u].push_back(now);
}
memset(e,0,sizeof(e));
int dis1=SPFA(n); //long long
swapg();
int dis2=SPFA(n); //long long
printf("%d\n",dis1+dis2); // lld%
}
}

HDU 1535 Invitation Cards (POJ 1511)的更多相关文章

  1. HDU 1535 Invitation Cards(最短路 spfa)

    题目链接: 传送门 Invitation Cards Time Limit: 5000MS     Memory Limit: 32768 K Description In the age of te ...

  2. hdu 1535 Invitation Cards(spfa)

    Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  3. poj 1511 Invitation Cards (最短路)

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

  4. HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...

  5. POJ1511:Invitation Cards(最短路)

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 34743   Accepted: 114 ...

  6. hdu 1535 Invitation Cards(SPFA)

    Invitation Cards Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other) T ...

  7. HDU 1535 Invitation Cards (最短路)

    题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...

  8. hdu 1535 Invitation Cards (最短路径)

    Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  9. HDU - 1535 Invitation Cards 前向星SPFA

    Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...

随机推荐

  1. 我的Android进阶之旅------>HTTP 返回状态值详解

    (本文转载于:http://blog.csdn.net/ithomer/article/details/10240351) 当用户点击或搜索引擎向网站服务器发出浏览请求时,服务器将返回Http Hea ...

  2. Js脚本实现选项卡的实例

    效果演示: 具体代码: <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http:/ ...

  3. GTest交流与经验总结

    GTest交流与经验总结 原文见:   http://starsourcingsolutions.com/myblog/?p=159

  4. JS中setTimeout()的使用方法具体解释

    1. SetTimeOut()              1.1 SetTimeOut()语法样例              1.2 用SetTimeOut()运行Function           ...

  5. Random Teams

    n participants of the competition were split into m teams in some manner so that each team has at le ...

  6. JDK 安装环境配置(ubuntu)

    在Ubuntu 上安装jdk,先去官网下载相对应的tar包 网址:(这是jdk1.8) http://www.oracle.com/technetwork/java/javase/downloads/ ...

  7. 基于visual Studio2013解决C语言竞赛题之1031猜数

          题目 解决代码及点评 /* 31. 猜号码∶由随机函数产生一个1至1000之间的整数,让人猜之. 计算机仅回答人猜的数大.小还是相等,当人猜对时, 由计算机打印出人 ...

  8. Cookie 路径在本机测试及服务器部署,在浏览器处理方式上的不同

    Table of Contents 1 问题场景 2 解决过程 2.1 cookie是否设置成功 2.2 cookie是否上传到服务器 3 总结 1 问题场景 最近在学用Python进行web开发,写 ...

  9. Androidclient与服务端(jsp)之间json的传输与解析【附效果图附源代码】

    近期有个项目须要用到json的传输,之前不是太了解,在网上找了些相关资料,写了一个小小的demo,能够实现基本功能:androidclient发送json到服务端,服务端使用jsp接收,解析后以jso ...

  10. Cookie例子

    马士兵老师的~~ cookie是服务器将信息保存在客户端的一个表示方式 名-值 服务器只能写入文档文件 每个浏览器都有唯一的标识号 且每个浏览器只允许访问与自身相关的cookie的内容 cookie分 ...