比赛 20161114 评测结果 RRRRRRRRRR
题目名称 输出全靠花 最终得分 0
用户昵称 123 运行时间 0.003 s
代码语言 C++ 内存使用 77.54 MiB
提交时间 2016-11-14 11:50:25
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
class as{
public:
	int y[1001],x;
};
as ya[10015]={0};
int ljb[10150][1001];
int yb[10015]={0};
int zd[10015]={0};
int yc[10015]={0};
int lu[10015]={0};
int lub[10015]={0};
int n,m,k;
int main(){
	freopen ("tubea.in","r",stdin);
	freopen ("tubea.out","w",stdout);
	int a,b,c,d,e,f;
	cin>>n>>m;
	for (a=1;a<=m;a++)
	{
		cin>>b>>c>>d;
		lu[a]=b;
		lub[a]=c;
		ljb[b][c]=d;
		ljb[c][b]=d;
	}
	cin>>k;
	for (a=1;a<=k;a++)
		cin>>yb[a]>>yc[a];
	int jib;
	int fq[10000]={0};
	for (a=1;a<=n;a++)
	{
		if(ljb[1][a]!=0)
			zd[a]=ljb[1][a];
		else
			if(a!=1)
			zd[a]=1000000;
	}
	int s[10015]={0};
	s[1]=1;
	int jia;
	jia=1;
	for (a=2;a<=n;a++)
	{
		d=0x7FFFFFFF;
		for (b=1;b<=n;b++)
		{
			if(d>zd[b]&&s[b]==0)
			{
				d=zd[d];
				jib=b;
			}
		}
		for (b=1;b<=n;b++)
		{
			if(b!=jib&&ljb[jib][b]!=0&&zd[b]>zd[jib]+ljb[jib][b])
			{
				zd[b]=zd[jib]+ljb[jib][b];
				fq[b]=jib;
			}
		}
		s[jib]=1;
		fq[jib]=jia;
		jia=jib;
	}
	int j;
	for (a=1;a<=n;a++)
	{
		ya[a].x=a;
		ya[a].y[a]=1;
		j=fq[a];
		for (;;)
		{
			if(j==1||j==0)
			{
				ya[a].y[1]=1;
				break;
			}
			ya[a].y[j]=1;
			j=fq[j];
		}
	}
	int ans;
	for (a=1;a<=n;a++)
		ans=ans+zd[a];
	cout<<ans<<endl;
	for (a=1;a<=k;a++)
	{
		ans=0;
		for (b=1;b<=n;b++)
		{
			if(ya[b].y[lu[yb[a]]]==1&&ya[b].y[lub[yb[a]]]==1)
			{
				zd[ya[b].x]=zd[ya[b].x]-(ljb[lu[yb[a]]][lub[yb[a]]]-yc[a]);
				
			}
			ans=ans+zd[ya[b].x];
		}
		ljb[lu[yb[a]]][lub[yb[a]]]=yc[a];
		ljb[lub[yb[a]]][lu[yb[a]]]=yc[a];
		cout<<ans<<endl;
	}
	return 0;
}