#include<iostream>
#include<algorithm>
using namespace std;
int Map[100][100],Value[100];
bool Mark[100];
int n,s,t;//if Max was defined here things will be much different now!
int CP(int x)
{
//if(Mark[x])
//return Value[x];
if(x==1)
{
//Mark[1]=true;
//Value[1]=0;
return 0;
}
int Max=0;
for(int i=1;i<=n;i++)
{
if(Map[i][x])
{
//cout<<i<<" ";
//cout<<Max<<" ";
Max=max(CP(i)+Map[i][x],Max);
//cout<<Max<<endl;
}
}
//Mark[x]=true;
//Value[x]=Max;
return Max;
}
void Solve()
{
int m;
memset(Map,0,sizeof(Map));
memset(Mark,0,sizeof(Mark));
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>s>>t;
cin>>Map[s][t];//now I find the problem
}
int num;
while(cin>>num)
cout<<CP(num)<<endl;
}
int main()
{
Solve();
return 0;
}
#include<algorithm>
using namespace std;
int Map[100][100],Value[100];
bool Mark[100];
int n,s,t;//if Max was defined here things will be much different now!
int CP(int x)
{
//if(Mark[x])
//return Value[x];
if(x==1)
{
//Mark[1]=true;
//Value[1]=0;
return 0;
}
int Max=0;
for(int i=1;i<=n;i++)
{
if(Map[i][x])
{
//cout<<i<<" ";
//cout<<Max<<" ";
Max=max(CP(i)+Map[i][x],Max);
//cout<<Max<<endl;
}
}
//Mark[x]=true;
//Value[x]=Max;
return Max;
}
void Solve()
{
int m;
memset(Map,0,sizeof(Map));
memset(Mark,0,sizeof(Mark));
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>s>>t;
cin>>Map[s][t];//now I find the problem
}
int num;
while(cin>>num)
cout<<CP(num)<<endl;
}
int main()
{
Solve();
return 0;
}