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 ...
随机推荐
- php 使用curl发起https请求
今天一个同事反映,使用curl发起https请求的时候报错:“SSL certificate problem, verify that the CA cert is OK. Details: erro ...
- Hadoop在Windows下的安装配置
由于本人近期近期一段时间 都在学习Hadoop,接触了比較多的理论,可是想要深入的去学习Hadoop整个平台,那就必须实战的训练,首先第一步,当然是先搭建好一个Hadoop平台为先.可是比較坑爹的是. ...
- PHP - 设置地址栏小图标
效果: 1/把icon图标直接放到根目录. 2/在header标签中写下: <link rel="icon" type="image/x-icon" hr ...
- 配置SAP 采购合同审批
需求: 采购合同类型是MK,采购组织是POSC,采购组PGC,标识:估计价格是空,总价有值0.00 - 9999999999.00 RMB 满足以上条件的时候需要审批该合同. 配置: spro-> ...
- BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛( dp )
水题...忘了取模就没1A了.... --------------------------------------------------------------------------- #incl ...
- checkbox探究
介绍checkbox checkbox: A check box. You must use the value attribute to define the value submitted by ...
- vbox要手动mount才能挂载windows的共享文件夹(好用,不用安装samba了)
mount -t vboxsf BaiduShare /mnt/bdshare/ 我按照这篇文章成功: http://www.wuji8.com/meta/448016166.html 其它参考: h ...
- hdu2489 Minimal Ratio Tree
hdu2489 Minimal Ratio Tree 题意:一个 至多 n=15 的 完全图 ,求 含有 m 个节点的树 使 边权和 除 点权和 最小 题解:枚举 m 个 点 ,然后 求 最小生成树 ...
- 监听手机晃动(摇一摇)SensorEventListener
import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; ...
- 免插件打造wordpress投稿页面
一.新建投稿页面模板 把主题的 page.php 另存为 tougao.php,并且在第一行的 <?php 之后添加模板的标识注释: /* Template Name: tougao */ 紧接 ...