这题怎么做?求助
题目传送门
已有代码
#include<bits/stdc++.h>
using namespace std;
#define MAXSIZE 105;
int v[MAXSIZE],w[MAXSIZE],head[MAXSIZE],next[MAXSIZE],tot=0;
int d[MAXSIZE];
void bfs(int x){
queue<int>q;
q.push(x);d[x]=1;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=head[u];i;i=next[i]){
int y=v[i];
if(d[y])continue;
d[y]=d[u]+1;
q.push(y);
}
}
}
void add_edge(int x,int y,int z){//建立(x,y)边,权值为z
v[++tot]=y;
w[tot]=z;//权值
next[tot]=head[x],head[x]=tot;//在链首x处插入节点y
}
int main(){
int n,m,a,b,c;//c为权值
cin>>n>>m;
for(int i=1;i<=m;i++){//输入边
cin>>a>>b>>c;
add_edge(a,b,c)
}
}