Topic Portal
1 /*2 Shortest way: Not only scan the edges, but also scan the points; There are two cases, one is just at the midpoint, that is, from the u,v, then the last/23 there is a different from the u,v, both of the distance is L4 The template was wrong and it was a long time: (5 */6#include <cstdio>7#include <algorithm>8#include <cstring>9#include <cmath>Ten#include <vector> One#include <queue> A using namespacestd; - - Const intMAXN = 1e5 +Ten; the Const intINF =0x3f3f3f3f; - intD[MAXN]; - intCNT[MAXN]; - BOOLVIS[MAXN]; +vector<pair<int,int> >G[MAXN]; - intN, M, S, l, ans, ans2; + A voidSPFA (void) { atmemset (Vis,false,sizeof(Vis)); -memset (d, INF,sizeof(d)); D[s] =0; -queue<int>Q; Q.push (s); - while(!Q.empty ()) { - intU =Q.front (); Q.pop (); -Vis[u] =false; in for(intI=0; I<g[u].size (); ++i) { - intv = g[u][i].first;intW =G[u][i].second; to if(D[v] > D[u] +W) { +D[V] = D[u] +W; - if(!Vis[v]) { theVIS[V] =true; Q.push (v); * } $ } Panax Notoginseng } - } the } + A intMainvoid) {//codeforces Round #103 (Div. 2) D. Missile Silos the //freopen ("spfa.in", "R", stdin); + - while(SCANF ("%d%d%d", &n, &m, &s) = =3) { $ for(intI=1; i<=m; ++i) { $ intU, V, W; scanf ("%d%d%d", &u, &v, &W); - G[u].push_back (Make_pair (V, W)); G[v].push_back (Make_pair (U, W)); - } thescanf ("%d", &l); SPFA (); - WuyiAns = Ans2 =0; the for(intI=1; i<=n; ++i) { - for(intj=0; J<g[i].size (); ++j) { Wu intU = i, V = g[i][j].first, w =G[i][j].second; - if(D[u] < L && L-d[u] <W) { About if(W-(L-d[u]) + d[v] > L) ans++; $ Else if(D[u] + d[v] + W = =2* L) ans2++; - } - } - if(D[i] = = L) ans++; A } +printf ("%d\n", ans + ans2/2); the } - $ return 0; the}
Shortest way Codeforces Round #103 (Div. 2) D. Missile Silos