UVa 544-heavy Cargo

Source: Internet
Author: User

Title: There is an unlimited load of trucks to transport goods, in the city each road has a maximum capacity to withstand the weight,

Now use trucks to transport goods from one city to another, asking for the maximum shipping weight.

Analysis: graph theory, shortest path, minimum spanning tree. Find a path from the starting point to the end point, making the narrowest section the widest.

It spreads from the beginning to the periphery, just like the Dijkstra algorithm and the prime algorithm, only maintaining the maximum value.

(If the above method is not correct, it exists at a certain point, after which the determination point can update it, then at that point should be found first)

Description: The road is bidirectional and the repeating path is considered to be expansion, addition and disposal.

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;/*hash_satrt*/typedef struct Hash_node{int Id;char name[31];hash_ Node*next;} Hash_node;hash_node node[202];hash_node* list[10007];int list_size = 0;void hash_initial () {list_size = 0;memset (Li St, 0, sizeof (List)), memset (node, 0, sizeof (node));} int Hash_hash (char *word) {int value = 0;for (int i = 0; word[i]; + + i) value = value * Word[i]% 10007;return value;} int Hash_find (char *word) {int value = Hash_hash (word); for (Hash_node *p = List[value]; p; p = p->next) if (!strcmp (p-& Gt;name, Word)) return p->id; Node[list_size].id = list_size;strcpy (node[list_size].name, Word); Node[list_size].next = List[value]; List[value] = &node[list_size ++];return list_size-1;}  /*hash_end*/int Maps[101][101];int Path[101],used[101];char buf1[31],buf2[31];int Deal (int s, int t, int n) {for (int i = 0; I < n; + + i) path[i] = uSed[i] = 0;path[s] = 10001;used[s] = 1;for (int i = 1; i < n; + + i) {for (int j = 0; J < N; + + j) if (!used[j] &A mp;& Maps[s][j]) path[j] = max (Path[j], min (Maps[s][j], path[s]); int max = 0;for (int j = 0; J < N; + + j) if (!us ED[J] && Max < path[j]) {s = j; Max = Path[j];} Used[s] = 1;} return path[t];} int main () {int m,n,p,a,b,case = 1;while (~scanf ("%d%d", &n,&m) && N) {hash_initial (); memset (maps, 0, sizeof (maps); for (int i = 0; i < m; + + i) {scanf ("%s%s%d", buf1,buf2,&p); a = Hash_find (BUF1); b = Hash_find (BUF2); MAPS[A][B] + = p;maps[b][a] + = p;} scanf ("%s%s", Buf1,buf2);p rintf ("Scenario #%d\n", Case +);p rintf ("%d tons\n\n", Deal (Hash_find (BUF1), Hash_find (buf2    ), n));} return 0;}


UVa 544-heavy Cargo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.