Can someone please tell me where my code fails for FIRST question.It gave me a correct answer verdict for test.But on submitting it gave a wrong answer.

```
#include <bits/stdc++.h>
void bfs(vector<int> &A,int u,vector<vector<pair<int,int>>> &graph,vector<int> &ans,vector<int> &path,vector<int> &par,bool vis[])
{
ans[u]=A[u-1];
queue<int> s;
vis[u]=1;
path[u]=0;
s.push(u);
while(!s.empty())
{
int x=s.front();
ans[u]=min(ans[u],A[x-1]+2*path[x]);
s.pop();
for(pair<int,int> p:graph[x])
{
par[p.first]=x;
if(!vis[p.first])
{
path[p.first]=path[x]+p.second;
vis[p.first]=1;
s.push(p.first);
}
}
}
}
vector<int> Solution::solve(vector<int> &A, vector<vector<int>> &B) {
vector<vector<pair<int,int>>> graph(A.size()+1,vector<pair<int,int>>());
vector<int> ans(A.size()+1);
vector<int> path(A.size()+1);
vector<int> par(A.size()+1);
bool vis[A.size()+1];
vector<int> res(A.size());
for(vector<int> v:B)
{
graph[v[0]].push_back(make_pair(v[1],v[2]));
graph[v[1]].push_back(make_pair(v[0],v[2]));
}
for(int i=1;i<=A.size();i++)
{
bfs(A,i,graph,ans,path,par,vis);
memset(vis,0,A.size()+1);
par.clear();
path.clear();
}
for(int i=1;i<=A.size();i++)
{
res[i-1]=ans[i];
}
return res;
}
```