题目:http://poj.org/problem?id=3013

求每个点到1的最短路。不是最小生成树。

总是WA。看讨论里说INF至少2e10,于是真的A了!

算一下,dis最大可能3276800000,于是开成3276800001,果然可A!还快了16ms(?)!

不过出现了: [Warning] this decimal constant is unsigned only in ISO C90 [enabled by default]。是什么意思呢?

总之以后设上界的时候还是略算一下。何况自己常用的0x 7 f f f f f f f也并不是十分大。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const long long INF=;
int T,n,m,head[],xnt,x,y,c[],z;
long long ans,dis[];
bool in[],flag;
struct Edge{
int next,to,w;
Edge(int ne=,int t=,int o=):next(ne),to(t),w(o) {}
}edge[];
queue<int> q;
void spfa()
{
while(q.size())q.pop();
memset(in,,sizeof in);
in[]=;dis[]=;
q.push();
while(q.size())
{
int k=q.front();q.pop();
in[k]=;///////!
for(int i=head[k],v;i;i=edge[i].next)
if(dis[k]+edge[i].w<dis[v=edge[i].to])
{
dis[v]=dis[k]+edge[i].w;
if(!in[v])
{
in[v]=;////////!
q.push(v);
}
}
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
memset(head,,sizeof head);
ans=;xnt=;flag=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)scanf("%d",&c[i]),dis[i]=INF;
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
edge[++xnt]=Edge(head[x],y,z);head[x]=xnt;
edge[++xnt]=Edge(head[y],x,z);head[y]=xnt;
}
spfa();
for(int i=;i<=n;i++)
{
if(dis[i]==INF)
{
flag=;break;
}
ans+=c[i]*dis[i];
}
if(flag) printf("No Answer\n");
else printf("%lld\n",ans);
}
return ;
}

POJ3013 Big Christmas Tree的更多相关文章

  1. POJ3013 Big Christmas Tree[转换 最短路]

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 23387   Accepted: 5 ...

  2. POJ3013 Big Christmas Tree(最短路径树)

    题目大概说给一张点和边都有权的图,现在要求其一棵以1结点为根的生成树使树的边权和最小,树边权 = 对应的图边权 * 树边末端点为根的子树所有结点对于图顶点的点权和. 要求∑(边权*子树点权和),等价于 ...

  3. Big Christmas Tree(poj-3013)最短路

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 25823   Accepted: 5 ...

  4. poj 3013 Big Christmas Tree

    Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 20974   Accepted: 4 ...

  5. poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra

    http://poj.org/problem?id=3013 Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total S ...

  6. poj 3013 Big Christmas Tree Djistra

    Big Christmas Tree 题意:图中每个节点和边都有权值,图中找出一颗树,树根为1使得 Σ(树中的节点到树根的距离)*(以该节点为子树的所有节点的权值之和) 结果最小: 分析:直接求出每个 ...

  7. POJ 3013 Big Christmas Tree(最短Dijkstra+优先级队列优化,SPFA)

    POJ 3013 Big Christmas Tree(最短路Dijkstra+优先队列优化,SPFA) ACM 题目地址:POJ 3013 题意:  圣诞树是由n个节点和e个边构成的,点编号1-n. ...

  8. POJ Big Christmas Tree(最短的基础)

    Big Christmas Tree 题目分析: 叫你构造一颗圣诞树,使得 (sum of weights of all descendant nodes) × (unit price of the ...

  9. HDU - 5156 Harry and Christmas tree

    题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=5156 题意 : 给一颗编号为1-n的以1为根的树, 已知有m个颜色的礼物分布在某些节点上(同一节点 ...

随机推荐

  1. 根据条件设置poplist的值集

    需求:在当前页面的pageButtonBar中有一个下拉选择框,选择框中的值集根据某些条件有不同. public class SupplierInfoReviewCO extends OAContro ...

  2. spring--boot数据库连接以及class建表

    Spring-Boot  数据库连接以及class建表 提前在pom.xml文件中添加:jpa,mysql资源 <dependency> <groupId>org.spring ...

  3. turbine是怎么收集指标数据的

    turbine是怎么收集指标数据的 我们通过spring cloud图形化dashboard是如何实现指标的收集展示的知道了,图形化的指标是从turbine获取到指标数据的.那么turbine的数据是 ...

  4. React-Router v4.0 hashRouter使用js跳转

    React-Router v4.0上已经不推荐使用hashRouter,主推browserRouter,但是因为使用browserRouter需要服务端配合可能造成不便,有时还是需要用到hashRou ...

  5. redis写入数据被转义问题

    1.phpredis扩展写入redis的数据发现“ \ 会被自动转义成\" \\. 如: 写入 dadaf"daf\dad  在redis命令行读出为 dadaf\"da ...

  6. learngin uboot design parameter recovery mechanism

    pseudocode: if( getenv(“uboot_env_init”)  !=  NULL){ if(uboot_env_init  !=  HAVE_INIT){ Set uboot_en ...

  7. Arrow function restore

    Arrow function restore 为什么叫Arrow Function?因为它的定义用的就是一个箭头: x => x * x 上面的箭头函数相当于: function (x) { r ...

  8. bzoj1650

    题解: 二分答案 然后贪心 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,l,a[N]; int pd(int x) ...

  9. noip2007-4

    首先预处理f[i][j]表示i到j的路径 然后枚举i,j,如果f[i][j]<=s,那么 寻找最大的k,计算路径距离 计算最短的 代码: #include<bits/stdc++.h> ...

  10. windows下运用批处理实现一键自动开启多个应用

    工作时,我每天早上到公司,打开自己的电脑,都会有几个固定的软件(myeclipse,飞信,firefox,foxmail等).文件夹和文件需要打开,每天如此,感到很烦,浪费时间做重复的工作,于是想到一 ...