直接贴代码了,可能有错误,如果发现了,请当没看见·················································
#include <iostream>
#include <vector>
#define MAX 100
using namespace std;
class node{
public:
int to;
int len;
}t;
int from,to,len;
vector<vector <node> > myVec(MAX);
int findWay(int from,int to){
vector<int> tVec;
bool check[MAX];
int minLen[MAX];
cout<<"The Min Way Is:";
memset(minLen,0,sizeof(minLen));
memset(check,0,sizeof(check));
check[0]=true;
tVec.clear();
tVec.push_back(from);
while(tVec.size()!=0){
int node = tVec[0];
tVec.erase(tVec.begin());
for(int i=0;i<myVec[node].size();i++){
t=myVec[node][i];
//if (!check[t.to]){
if (t.len+minLen[node]<minLen[t.to]||minLen[t.to]==0){
minLen[t.to]=t.len+minLen[node];
tVec.push_back(t.to);
check[t.to]=true;
}
//}
}
}
return minLen[to];
}
int main()
{
while(true){
cin>>from;
if (from==-1){
cout<<"Input Over"<<endl;
break;
}
cin>>to>>len;
t.to=to;
t.len=len;
myVec[from].push_back(t);
}
while(true){
cin>>from>>to;
cout<<findWay(from,to)<<endl;
}
}