记录编号 |
229826 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[省常中2011S4] 聖誕節 |
最终得分 |
100 |
用户昵称 |
liu_runda |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.067 s |
提交时间 |
2016-02-20 19:47:28 |
内存使用 |
1.66 MiB |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- #include<queue>
- using namespace std;
- int w[50020];
- int d[50020];
- struct edge{
- int to,next,w;
- }lst[100040];int len =1;
- int first[50020];
- void insert(int a,int b,int w){
- lst[len].next=first[a];
- lst[len].to=b;
- lst[len].w=w;
- first[a]=len++;
- }
- bool inq[50020];
- int main(){
- freopen("chris.in","r",stdin);
- freopen("chris.out","w",stdout);
- int n,m;
- scanf("%d %d",&n,&m);
- for(int i=1;i<=n;++i)scanf("%d",&w[i]);
- int a,b,c;
- for(int i=0;i<m;++i){
- scanf("%d %d %d",&a,&b,&c);
- insert(a,b,c);
- insert(b,a,c);
- }
- queue<int> q;
- memset(d,63,sizeof(d));
- d[1]=0;
- for(int pt=first[1];pt;pt=lst[pt].next){
-
- q.push(lst[pt].to);
- inq[lst[pt].to]=true;
- if(d[lst[pt].to]>lst[pt].w)d[lst[pt].to]=lst[pt].w;
-
- }
- while(!q.empty()){
- int v=q.front();
- for(int pt=first[v];pt;pt=lst[pt].next){
- if(d[v]+lst[pt].w<d[lst[pt].to]){
- d[lst[pt].to]=d[v]+lst[pt].w;
- if(!inq[lst[pt].to]){
- inq[lst[pt].to]=true;
- q.push(lst[pt].to);
- }
- }
- }
- inq[v]=false;
- q.pop();
- }
- long long ans=0;
- for(int i=2;i<=n;++i)ans+=w[i]*d[i];
- printf("%lld",ans);
- fclose(stdin);fclose(stdout);
- return 0;
- }