只是想知道它缺乏的地方。
我尝试了很多但没有得到解决方案。请帮助,提前致谢!!
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
lli t,n,k,x,m,i,a,b,j,c,s,g,h;
lli minimum(lli dist[], bool sptSet[])
{
lli min = INT_MAX,min_index;
for (lli v = 0; v<n; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v],min_index = v;
return min_index;
}
lli answer(lli dist[],lli n)
{
for (lli i=0; i<n; i++)
printf("%lli ",dist[i]);
printf("\n");
}
void sourabhDijk(const vector<vector<int> >& graph,long long int src)
{
lli dist[n];
bool sptSet[n];
for (lli i=0;i<n;i++)
dist[i] = INT_MAX, sptSet[i] = false;
dist[src] = 0;
for (lli count=0; count<n-1;count++)
{
lli u = minimum(dist, sptSet);
sptSet[u] = true;
for (lli v=0;v<n;v++)
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u]
+ graph[u][v]<dist[v])
dist[v] = dist[u] + graph[u][v];
}
answer(dist,n);
}
int main(){
cin>>t;
while(t--){
cin>>n>>k>>x>>m>>s;
vector<pair<lli,lli> > adj[n];
vector<pair<lli,lli> >::iterator it;
for(i=0;i<k;++i){
for(j=i+1;j<k;++j){
adj[i].push_back(make_pair(j,x));
}
}
for(i=0;i<m;++i){
cin>>a>>b>>c;
adj[a-1].push_back(make_pair(b-1,c));
}
vector<vector<int> > v(n, vector<int>(n));
for(i=0;i<n;++i){
for(it = adj[i].begin();it!=adj[i].end();++it){
g=it->first;
h=it->second;
v[i][g]=h;
v[g][i]=h;
}
}
sourabhDijk(v,s-1);
v.clear();
}
}