I changed it as follows and now it gives wrong answer.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define mp make_pair
#define MAX 100005
#define mod 1000000007
#define pb push_back
#define INF 1000005
#define pii pair<int,int>
vector< vector<int> > graph;
vector< vector<int> > weight;
vector<int> cost;
map<string,int> my;
int n;
struct cmp
{
bool operator()(const int &lhs,const int &rhs) const
{
return cost[lhs]>cost[rhs];
}
};
int min(int a,int b)
{
if(a<b)
return a;
return b;
}
//priority_queue<int,vector<int>,cmp> pq;
int dijkstra(int from, int to)
{
priority_queue<int,vector<int>,cmp> pq;
vector<bool> vis(n+1,false);
vis[from]=true;
cost[from]=0;
pq.push(from);
while(!pq.empty())
{
int cur=pq.top();
pq.pop();
vis[cur]=true;
for(int i=0;i<graph[cur].size();i++)
{
if(!vis[graph[cur][i]]&&(cost[graph[cur][i]]>(cost[cur]+weight[cur][i])))
{
cost[graph[cur][i]]=cost[cur]+weight[cur][i];
pq.push(graph[cur][i]);
}
}
}
//while(!pq.empty())
// pq.pop();
return cost[to];
}
int main()
{
//freopen ("input1.in","r",stdin);
//freopen ("output22.txt","w",stdout);
int t,r,i,p,nr,cost2;
scanf("%d",&t);
while(t--)
{
char s[20];
scanf("%d",&n);
for(i=0;i<=n;i++)
{
graph.push_back(vector <int> ());
weight.push_back(vector <int> ());
}
for(i=0;i<=n;i++)
cost.pb(INT_MAX);
for(i=1;i<=n;i++)
{
scanf("%s%d",s,&p);
my[s]=i;
while(p--)
{
scanf("%d%d",&nr,&cost2);
graph[i].pb(nr);
weight[i].pb(cost2);
}
}
scanf("%d",&r);
while(r--)
{
char s1[20],s2[20];
scanf("%s%s",s1,s2);
printf("%d\n",dijkstra(my[s1],my[s2]));
}
cost.clear();
my.clear();
for(i=0;i<=n;i++)
{
graph[i].clear();
weight[i].clear();
}
}
return 0;
}