标签:io os sp for on bs amp size nbsp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
vector<int> e[2560],w[2560];
queue<int> q;
int T,C,ts,te,dist[2560];
bool vis[10001];
void spfa()
{
int x;
q.push(ts);
vis[ts]=1;
while(!q.empty())
{
x=q.front(),q.pop();
for(int i=0;i<e[x].size();i++)
if(w[x][i]+dist[x]<dist[e[x][i]])
{
dist[e[x][i]]=w[x][i]+dist[x];
if(!vis[e[x][i]])
{
vis[e[x][i]]=1;
q.push(e[x][i]);
}
}
vis[x]=0;
}
}
int main()
{
scanf("%d%d%d%d",&T,&C,&ts,&te);
memset(dist,0x3f,sizeof(dist));
for(int i=0;i<C;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
e[a].push_back(b);
e[b].push_back(a);
w[a].push_back(c);
w[b].push_back(c);
}
dist[ts]=0;
spfa();
printf("%d\n",dist[te]);
return 0;
}
标签:io os sp for on bs amp size nbsp
原文地址:http://www.cnblogs.com/a972290869/p/4101085.html