记录编号 312492 评测结果 AAAAA
题目名称 [HAOI 2005]希望小学 最终得分 100
用户昵称 GravatarHakurou! 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2016-09-26 16:12:24 内存使用 0.00 MiB
显示代码纯文本
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define GET (ch>='0'&&ch<='9')
#define FA(i,a,b) for(i=a;i<=b;i++)
#define FL(i,a,b) for(i=a;i>=b;i--) 
typedef long long ll;
const int miau=160325521;
using namespace std;
int i,j,k;
void in(int &x)
{
    char ch=getchar();x=0;int f=1;
    while(!GET)f=ch=='-'?-1:f,ch=getchar();
    while(GET)x=x*10+ch-'0',ch=getchar();x*=f;
}
int main(){;}
int n,m;
int ba,bb,bc,ga,gb,gc;
int b[500],g[500];
int from,to,ra,rb,rc;
int f[500][500];
void pre(int n)
{
	FA(i,1,n)
	{
		FA(j,1,n)
		{
			if(i==j)f[i][j]=0;
			else f[i][j]=miau;
		}
	}
}
void floyd(int n)
{
	int i;
	FA(i,1,n)
	{
		FA(j,1,n)
		{
			FA(k,1,n)
			{
				if(f[i][j]+f[j][k]<=f[i][k])f[i][k]=f[i][j]+f[j][k];
			}
		}
	}
	FL(i,n,1)
	{
		FL(j,n,1)
		{
			FL(k,n,1)
			{
				if(f[i][j]+f[j][k]<=f[i][k])f[i][k]=f[i][j]+f[j][k];
			}
		} 
	}
}
void printfloyd(int n)
{
	FA(i,1,n)
	{
		FA(j,1,n)
		{
			printf("%d ",f[i][j]);
		}
		printf("\n");
	}
}
int A()
{
	freopen("hopeschool.in","r",stdin);
	freopen("hopeschool.out","w",stdout);
	in(n);in(ba);in(bb);in(bc);in(ga);in(gb);in(gc);
	pre(n);
	FA(i,1,n)in(b[i]);
	FA(i,1,n)in(g[i]);
	in(m);
	FA(i,1,m)
	{
		in(from);in(to);in(ra);in(rb);in(rc);
		f[from][to]=b[from]*(ra*ba+rb*bb+rc*bc)+g[from]*(ra*ga+rb*gb+rc*gc);
		f[to][from]=b[to]*(ra*ba+rc*bb+rb*bc)+g[to]*(ra*ga+rc*gb+rb*gc);
	}
	floyd(n);
	//printfloyd(n);
	int dis[500];
	FA(i,1,n)dis[i]=0;
	FA(i,1,n)
	{
		FA(j,1,n)
		{
			FA(k,1,n)
			{
				if(k==i)
				{
					dis[i]+=f[j][k];
				}
			}
		}
	}
	//FA(i,1,n)printf("%d ",dis[i]);
	int min=miau;
	int num;
	FA(i,1,n)
	{
		if(dis[i]<min)
		{
			min=dis[i];
			num=i;
		}
	}
	printf("%d\n",num);
	return 0;
}
int B=A();