题目: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. POJ 3481 splay模板

    最后撸一发splay. 之前用treap撸的,现在splay也找到感觉了,果然不同凡响,两者之间差别与精妙之处各有其精髓! 真心赞一个! POJ平衡树的题目还是比较少,只能挑之前做过的捏一捏.但是收获 ...

  2. kubernetes资源清单入门

    创建nginx容器: kubectl run nginx-deploy8 --image=nginx:1.14-alpine --port=80 --replicas=2 deployment &qu ...

  3. pos提交提交数据时碰到Django csrf

    我的github(PS:希望star):https://github.com/thWinterSun/v-admin 最近在用Vue写前端代码,再用vue-resource向后台提交数据.项目后台是用 ...

  4. sgu108. Self-numbers 2 滚动数组 打表 难度:1

    108. Self-numbers 2 time limit per test: 0.5 sec. memory limit per test: 4096 KB In 1949 the Indian ...

  5. python3 win10_x64 安装pcapy

    稀里糊涂就装上了 大概记录一下都有什么. visual studio build tools 2015 下载地址: http://landinghub.visualstudio.com/visual- ...

  6. L1-042 日期格式化

    世界上不同国家有不同的写日期的习惯.比如美国人习惯写成“月-日-年”,而中国人习惯写成“年-月-日”.下面请你写个程序,自动把读入的美国格式的日期改写成中国习惯的日期. 输入格式: 输入在一行中按照“ ...

  7. 使用MyEclipse开发Java EE应用:EJB项目开发初探(下)

    你开学,我放价!MyEclipse线上狂欢继续!火热开启中>> [MyEclipse最新版下载] 三.EJB 3.x项目中的持久性支持 当创建EJB 3.x项目时,作为选项您可以添加JPA ...

  8. 【DevExpress v17.2新功能预告】DevExtreme ASP.NET MVC新的强类型HTML Helpers

    在ASP.NET MVC中构建视图时,强类型HTML helpers非常有用.像@Html.TextBoxFor(m => m.FirstName)这样内置的Helper方法已经存在很长时间了, ...

  9. pl/sql中误删表中数据并提交恢复办法

    最近在操作表中数据时,删除了表中数据,但是又想恢复,后来查到了官方的一篇文档,发现还蛮有用的,如下: 在pl/sql中运行,select * from A as of TIMESTAMP to_tim ...

  10. Linux:查看进程运行时间

    查看进程运行时间 应用ps命令,加选项-Ao,加参数,最后过滤. ps -Ao pid,tty,user,stime,etime,comm,args| grep firefox pid:进程ID tt ...