bool st[N];//是否在队列中
int d[N];//到起点的距离
void dj(int S,int T)//从S到T
{queue<int>q;q.push(S);memset(d,0x3f,sizeof d);d[S] = 0;while (!q.empty()){int ver = q.front();q.pop();st[ver] = false;//出队for (int i = h[ver];i != -1;i = h[i]){int x = e[i];int dist = w[i];//距离if (d[x] > d[ver] + dist){d[x] = d[ver] + dist;if (!st[x]) q.push(x);}}}
}