#include<stdio.h>
void findans(long int u);
long int j,adj[1000][1000],n,m,k,lp,total,test,t1,i,max=0,node;
long int LU[100002];
int main()
{
// int test,t1;
// freopen("F:\\a.txt","r",stdin);
scanf("%ld",&test);
for(t1=1;t1<=test;t1++)
{
total=0;
node=0;
scanf("%ld%ld",&n,&m);
for(lp=0;lp<n;lp++)
scanf("%ld",&LU[lp]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
adj[i][j]=0;
}
}
for(k=0;k<m;k++)
{
scanf("%ld%ld",&i,&j);
adj[i][j]=1;
}
findans(0);
}
return 0;
}
void findans(long int u)
{
int ii,str;
max=0;
for(ii=0;ii<n;ii++)
{
if(adj[u][ii]==1)
{
if(LU[max]<LU[ii])
max=ii;
}
}
if(max!=0)
node=max;
if(max==0)
{
printf("Case %ld: ",t1);
printf("%ld %ld\n",total,node);
return;
}
total=total+LU[max];
findans(max);
}
void findans(long int u);
long int j,adj[1000][1000],n,m,k,lp,total,test,t1,i,max=0,node;
long int LU[100002];
int main()
{
// int test,t1;
// freopen("F:\\a.txt","r",stdin);
scanf("%ld",&test);
for(t1=1;t1<=test;t1++)
{
total=0;
node=0;
scanf("%ld%ld",&n,&m);
for(lp=0;lp<n;lp++)
scanf("%ld",&LU[lp]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
adj[i][j]=0;
}
}
for(k=0;k<m;k++)
{
scanf("%ld%ld",&i,&j);
adj[i][j]=1;
}
findans(0);
}
return 0;
}
void findans(long int u)
{
int ii,str;
max=0;
for(ii=0;ii<n;ii++)
{
if(adj[u][ii]==1)
{
if(LU[max]<LU[ii])
max=ii;
}
}
if(max!=0)
node=max;
if(max==0)
{
printf("Case %ld: ",t1);
printf("%ld %ld\n",total,node);
return;
}
total=total+LU[max];
findans(max);
}
No comments:
Post a Comment