题目链接:https://www.luogu.org/problemnew/show/P3063#sub
我很好奇这道题为什么没被收入SPFA好题
1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <algorithm> 5 using namespace std; 6 const int maxn = 20001; 7 const int inf = 0x7fffffff-1; 8 int n, m, s, f, x, k, ans = inf, dis[maxn], c[maxn]; 9 bool vis[maxn]; 10 struct edge{ 11 int to, next, len, from, l; 12 }e[maxn]; 13 int head[maxn], cnt; 14 void add(int u, int v, int w, int l) 15 { 16 e[++cnt].from = u; 17 e[cnt].to = v; 18 e[cnt].len = w; 19 e[cnt].l = l; 20 e[cnt].next = head[u]; 21 head[u] = cnt; 22 } 23 int SPFA(int k) 24 { 25 queue<int> q; 26 memset(vis,0,sizeof(vis)); 27 memset(dis,127,sizeof(dis)); 28 dis[s] = 0; 29 q.push(s); 30 vis[s] = 1; 31 while(!q.empty()) 32 { 33 int now = q.front(); 34 q.pop(); 35 vis[now] = 0; 36 for(int i = head[now]; i ; i = e[i].next) 37 { 38 if(dis[e[i].to] > dis[now]+e[i].len && e[i].l >= k) 39 { 40 dis[e[i].to] = dis[now]+e[i].len; 41 if(!vis[e[i].to]) 42 { 43 vis[e[i].to] = 1; 44 q.push(e[i].to); 45 } 46 } 47 } 48 } 49 } 50 int main() 51 { 52 scanf("%d%d%d",&n,&m,&x); 53 for(int i = 1; i <= m; i++) 54 { 55 int u,v,w,l; 56 scanf("%d%d%d%d",&u,&v,&w,&l); 57 add(u,v,w,l); 58 add(v,u,w,l); 59 c[i] = l; 60 } 61 sort(c+1,c+m+1); 62 s = 1, f = n; 63 for(int i = 1; i <= m; i++) 64 { 65 SPFA(c[i]); 66 ans = min(ans, dis[f]+x/c[i]); 67 } 68 printf("%d",ans); 69 }