记录编号 229838 评测结果 AAAAAAAAAA
题目名称 [省常中2011S4] 聖誕節 最终得分 100
用户昵称 GravatarYGOI_真神名曰驴蛋蛋 是否通过 通过
代码语言 C++ 运行时间 0.112 s
提交时间 2016-02-20 19:52:55 内存使用 15.73 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct line{
	int to;
	int dis;
	int next;
	line(){to=-1;dis=0x7ffffff;next=-1;}
};
struct Node{
	int place;
	int dis;
	Node(int a,int b){place=a,dis=b;}
	bool operator < (Node a)const{return dis>a.dis;}
};
struct Path{
	int tot;
	int point;
	int lens;
	int points[500010];
	int head[500010];
	int dis[500010];
	line table[1000010];
	Path(){tot=0;point=0;lens=0;memset(head,-1,sizeof(head));}
	void adder(int from,int to,int dis){
		table[++tot].next=head[from];
		table[tot].dis=dis;
		table[tot].to=to;
		head[from]=tot;
	}
	void dijsa(int from){
		priority_queue<Node>q;
		memset(dis,63,sizeof(dis));
		dis[from]=0;
		q.push(Node(from,0));
		while(!q.empty()){
			Node ppt=q.top();
			q.pop();
			if(ppt.dis!=dis[ppt.place])continue;
			for(int i=head[ppt.place];i!=-1;i=table[i].next){
				if(dis[table[i].to]>dis[ppt.place]+table[i].dis){
					dis[table[i].to]=dis[ppt.place]+table[i].dis;
					q.push(Node(table[i].to,dis[table[i].to]));
				}
			}
		}
	}
	void doing(){
		int a,b,c,d,e;
		scanf("%d%d",&a,&b);
		for(int i=1;i<=a;i++)scanf("%d",&c),points[i]=c;
		for(int i=1;i<=b;i++)scanf("%d%d%d",&c,&d,&e),adder(c,d,e),adder(d,c,e);
		dijsa(1);
		long long int ans=0;
		for(int i=2;i<=a;i++)ans+=dis[i]*points[i];
		printf("%lld",ans);
	}
}arcv;
int main(){
	freopen("chris.in","r",stdin);
	freopen("chris.out","w",stdout);
	arcv.doing();
	//while(1);
	fclose(stdin);
	fclose(stdout);
	return 0;
}