HDU 1535 Invitation Cards (POJ 1511)
两次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)的更多相关文章
- HDU 1535 Invitation Cards(最短路 spfa)
题目链接: 传送门 Invitation Cards Time Limit: 5000MS Memory Limit: 32768 K Description In the age of te ...
- hdu 1535 Invitation Cards(spfa)
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- poj 1511 Invitation Cards (最短路)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 33435 Accepted: 111 ...
- HDU 1535 Invitation Cards(逆向思维+邻接表+优先队列的Dijkstra算法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1535 Problem Description In the age of television, n ...
- POJ1511:Invitation Cards(最短路)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 34743 Accepted: 114 ...
- hdu 1535 Invitation Cards(SPFA)
Invitation Cards Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) T ...
- HDU 1535 Invitation Cards (最短路)
题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...
- hdu 1535 Invitation Cards (最短路径)
Invitation Cards Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU - 1535 Invitation Cards 前向星SPFA
Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...
随机推荐
- Robot Framework与Web界面自动化测试学习笔记:利用xpath定位元素
在rf中,利用selinum2的关键字进行用例编写时,很多关键字的参数是html元素的定位标识. 最简单的方式,是通过id 或name来描述元素定位信息,如 click button id=l ...
- 配置Jenkins的slave节点的详细步骤适合windows等其他平台(转)
@ 新建一个slave节点在Jenkins服务器上 1,进入Jenkins的主界面,进入“Manage Jenkins” 页面: 2,点击如下图中的“Manage Nodes”: 3,进入页面后点 ...
- Oracle多实例的配置方法
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME /dbhome_2) (PROGRAM ...
- (step8.2.6)hdu 1848(Fibonacci again and again——组合博弈)
题目大意:输入3个整数m,n,p,分别表示3堆石头中的石头个数 解题思路: 1)斐波那契数列的第16个数fib[16] == 1597 2)(sg[m]^sg[n]^sg[p]) .一定要加括号, ...
- Codeforces Round #189 (Div. 2)
题目地址:http://codeforces.com/contest/320 第一题:基本题,判断mod 1000,mod 100.,mod 10是不是等于144.14.1,直到为0 代码如下: #i ...
- C语言,变量与内存
一.数在计算机中的二进制表示 符号位:最高位为符号位,正数该位为0,负数该位为1: 原码:原码就是符号位加上真值的绝对值, 即用第一位表示符号, 其余位表示值 反码:正数的反码是其本身:负数的反码是在 ...
- BZOJ 1342: [Baltic2007]Sound静音问题( 单调队列 )
一开始写了个RMQ然后就T了... 好吧正解是单调队列, 维护两个单调队列... ----------------------------------------------------------- ...
- Windows下用WinSCP传输数据到Linux上
Scenario:最近公司做的一个项目,UI部分我是使用python在编译时做localization的,是linux下运行的,但是开发是在windows下进行的每次编译后都要手动通过WinSCP这个 ...
- iOS "The sandbox is not in sync with the Podfile.lock"解决方式
更新Cocoapod之后出现故障: diff: /../Podfile.lock: No such file or directory diff: Manifest.lock: No such fil ...
- Swift - final关键字的介绍,以及使用场景
final关键字在大多数的编程语言中都存在,表示不允许对其修饰的内容进行继承或者重新操作.Swift中,final关键字可以在class.func和var前修饰. 通常大家都认为使用final可以更好 ...