记录编号 |
175635 |
评测结果 |
AAAAAAAAAA |
题目名称 |
圣诞树 |
最终得分 |
100 |
用户昵称 |
forever |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2015-08-06 15:46:21 |
内存使用 |
1.01 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int n,tot,aq[2000],num,dis[136],a[136];
int ru[300],lian[300][600],r,maxx;
bool v[300];
char s[350];
void bfs(int y)
{
queue<int>q;
memset(dis,0,sizeof(dis));
v[y]=1;
dis[y]=a[y];
q.push(y);
while(!q.empty())
{
int yu=q.front();
q.pop();
v[yu]=0;
if(!ru[yu])
{
if(dis[yu]>maxx)
maxx=dis[yu];
}
for(int i=1;i<=ru[yu];++i)
{
int h=lian[yu][i];
if(dis[h]<dis[yu]+a[h])
{ dis[h]=dis[yu]+a[h];
if(!v[h])
{
v[h]=1;
q.push(h);
}
}
}
}
}
int main()
{ freopen("treez.in","r",stdin);
freopen("treez.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%d",&a[i]);
if(i==n)
break;
gets(s);
int u=strlen(s);
for(int y=1;y<=u;y++)
{
if(s[y]>='0'&&s[y]<='9')
{
if(s[y+1]<'0'||s[y+1]>'9')
{
int yu=s[y]-'0';
ru[i]++;
lian[i][ru[i]++]=yu;
continue;
}
if(s[y+1]>='0'&&s[y+1]<='9'&&s[y+2]>='0'&&s[y+2]<='9')
{
int yu=(s[y]-'0')*100+(s[y+1]-'0')*10+s[y+2]-'0';
ru[i]++;
lian[i][ru[i]++]=yu;
y=y+2;
continue;
}
int yu=(s[y]-'0')*10+s[y+1]-'0';
ru[i]++;
lian[i][ru[i]++]=yu;
y=y+1;
}
}
}
for(int i=1;i<=n;++i)
bfs(i);
printf("%d",maxx);
return 0;
}