Topic Link: [POJ 1797]heavy TRANSPORTATION[SPFA]
The analysis:
For all paths from point 1 to N, the maximum size of the smallest capacity on the path.
Ideas for solving problems:
will be the shortest way of thinking change on the line. The Dis[i] Array records the smallest road capacity on the road from point 1 to I. Note Initialization of the DIS array.
Personal experience:
It was written because it was stuck in the initialization and tried several times.
The specific code is as follows:
#include <cstdio> #include <cstring> #include <iostream> #include <queue> using namespace std;
const int MAXN = 1E3 + 111;
struct n{int to, cap;
N (int A, int b) {to = A; cap = b;
}
};
Vector<n> G[MAXN];
int DIS[MAXN];
BOOL IN[MAXN];
void SPFA (int s) {queue<int> q;
Q.push (s);
for (int i = 0; i < g[s].size (); ++i) {N &e = g[s][i];
Dis[e.to] = E.cap;
Q.push (e.to);
In[e.to] = 1;
} In[s] = 1;
while (Q.size ()) {int cur = Q.front (); Q.pop (); in[cur] = 0;
for (int i = 0; i < g[cur].size (); ++i) {N &e = g[cur][i];
if (Dis[e.to] < min (Dis[cur], e.cap)) {dis[e.to] = min (dis[cur), e.cap);
if (!in[e.to]) {in[e.to] = 1;
Q.push (e.to);
()}}} int main () {int T, n, M; for (int kase = scanf ("%d", &t), Kase <= t; ++kase) {scanf ("%d%d", &n, &m);
for (int i = 1; I <= n; ++i) g[i].clear ();
while (M-) {int u, to, W;
scanf ("%d%d%d", &u, &to, &w);
G[u].push_back (N (to,w));
G[to].push_back (N (u,w));
} memset (dis, 0, sizeof (int) * (n + 10));
memset (in, 0, sizeof (BOOL) * (n + 10));
SPFA (1);
printf ("Scenario #%d:\n%d\n\n", Kase, Dis[n]);
return 0;
}