两次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. JVM调优总结(九)-新一代的垃圾回收算法

    垃圾回收的瓶颈 传统分代垃圾回收方式,已经在一定程度上把垃圾回收给应用带来的负担降到了最小,把应用的吞吐量推到了一个极限.但是他无法解决的一个问题,就是Full GC所带来的应用暂停.在一些对实时性要 ...

  2. 物理Data Guard主备切换步骤

    物理Data Guard角色转换步骤   Step  1   验证主库是否能执行角色转换到备库(原主库执行) SQL> SELECT SWITCHOVER_STATUS FROM V$DATAB ...

  3. android APP 中微信分享功能实现 的总结

    //花了很长时间最终完成了微信分享功能,中间走了很多弯路,在此做一下小结,希望对在应用中使用到微信分享的朋友有所帮助. 主要问题就是下面两个: 1.为什么运行了项目之后,微信分享只是闪了一下就没有了? ...

  4. IT忍者神龟之Oracle DBA经常使用查询吐血列举

    –1. 查询系统全部对象 select owner, object_name, object_type, created, last_ddl_time, timestamp, status from ...

  5. 利用d3.js绘制中国地图

    d3.js是一个比較强的数据可视化js工具. 利用它画了一幅中国地图,例如以下图所看到的: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3ZhcDE=/ ...

  6. HTML简单介绍及举例

    超文本标记语言(Hyper Text Markup Language,简称HTML)是为"网页创建和其他可在网页浏览器中看到的信息"设计的一种标记语言.HTML被用来结构化信息,也 ...

  7. Ch04 充满动作的控制器

    4.1  考察控制器和动作 4.1.1  IController与控制器基类 4.1.2  如何形成动作方法 4.2  哪些应该放在动作方法中 4.2.1  手动映射视图模型 4.2.2  输入验证 ...

  8. UML03-类图

    1.在类图中,聚合关系表达总体与局部的关系. 2.请根据下面的需求,画出用例图和类图. 系统允许管理员通过磁盘加载存货数据来运行存货清单报告: 管理员通过从磁盘加载存货数据.向磁盘保存存货数据来更新存 ...

  9. Mac 下安装配置Mysql

    在Mac 下载 Mysql Server : 参考:http://www.mysql.com/downloads/ 下载Mysql 安装程序 打开下载地址: http://www.mysql.com/ ...

  10. Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary lo

    mysql> show slave status\G *************************** 1. row ***************************         ...