两次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. EF 简单的 CRUD、分页 代码笔记

    添加: static void Main(string[] args)        {            CCDBEntities ccdbContext = new CCDBEntities( ...

  2. iOS 编程之 使用 Xcode6配置.pch文件

    刚上手 Xcode6 的人,总会发现之前在 6 之前常常会在“利用名-Prefix.pch”这个文件中来配置我们全局要用到的头文件,但是 xcode6 没有了,人家说,这类东西有时候也会出现1些稀里糊 ...

  3. Linux系统中如何添加自己的库文件路径

    库文件在连接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的.一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径,所以使用 ...

  4. perl $d = encode_utf8($r); $f = decode_json($d)

    [root@dr-mysql01 ~]# cat a1.pl my $url="http://192.168.32.101:3000/api/getcode?env=zj&phone ...

  5. 《Java虚拟机原理图解》1.3、class文件里的訪问标志、类索引、父类索引、接口索引集合

    讲完了class文件里的常量池,我们就相当于克服了class文件里最麻烦的模块了.如今,我们来看一下class文件里紧接着常量池后面的几个东西:訪问标志.类索引.父类索引.接口索引集合. 1. 訪问标 ...

  6. 80 多个 Linux 系统管理员必备的监控工具

    随着互联网行业的不断发展,各种监控工具多得不可胜数.这里列出网上最全的监控工具.让你可以拥有超过80种方式来管理你的机器.在本文中,我们主要包括以下方面: 命令行工具 网络相关内容 系统相关的监控工具 ...

  7. git-daemon的快捷搭建

    使用git-daemon进行git服务器搭建 1.安装git-daemon 前提是已经安装git sudo apt-get install git git-core 然后安装git-daemon su ...

  8. DButils工具类能够用来获取数据库连接向数据库插入更新删除对象2

    package com.ctl.util; import java.awt.Color; import java.awt.Font; import java.awt.Insets; import ja ...

  9. Win7安装vs2010失败

    提示: ------------------------------------------------------------------------------------------------ ...

  10. ABAP 向上取整和向下取整 CEIL & FLOOR

    下面是一段关于CEIL 和 FLOOR 的代码 DATA:a TYPE mseg-menge, b TYPE mseg-menge, c TYPE mseg-menge. a = '1.36'. b ...