POJ 1511 Invitation Cards

Source: Internet
Author: User

Description:

In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia is aware of this fact. They want to propagate theater and, the most of all, antique comedies. They has printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer have assigned exactly one bus stop and he or she stays there the whole day and gives invitation to P Eople travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing a nd robbery.

The transport system is very special:all lines be unidirectional and connect exactly. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g x:00 or x:30, where ' X ' denotes the hour. The fee for transport between and stops are given by special tables and are payable on the spot. The lines is planned in such a to, that's round trip (i.e. a journey starting and finishing at the same stop) passes Through a central Checkpoint Stop (CCS) where each passenger have to pass a thorough check including body scan.

All of the ACM student members leave the CCS morning. Each volunteer are to move to a predetermined stop to invite passengers. There is as many volunteers as stops. At the end of the day, all students travel back to CCS. You is to write a computer program this helps ACM to minimize the amount of money to pay every day for the transport of T Heir employees.

Input:

The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly the integers P and Q, 1 <= p,q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there is Q lines, each describing one bus line. Each of the lines contains exactly three numbers-the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices is positive integers the sum of which is smaller than 1000000000. You can also assume it's always possible to get from any stop to any other stop.

Output:

For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of it S volunteers.

Sample Input:

22 21 2 132 1 334 61 2 102 1 601 3 203 4 102 4 54 1 50

Sample Output:

46210
Test instructions: Some students are hired to distribute invitations, each time they go from the central station to other stations to distribute invitations, now to calculate how much the pay for them a day down, (from a to B station pay and B station to a station may be different, but in the end everyone is going back to the central station, This topic Central Station marking is 1), and POJ 3268 Silver Cow party Similar, are carried out two times SPFA algorithm, the difference is this time the data is larger, with adjacency table better.
#include <stdio.h>#include<queue>#include<string.h>#include<algorithm>using namespacestd;Const intn=1000010;Const intinf=0x3f3f3f3f;intD1[n], d2[n], vis[n], N, Head[n], K;structnode{intV, Flow, next;} No[n];structmode{intA, B, C;} Mo[n];voidInit (intd[]) {    inti;  for(i =1; I <= N; i++) {D[i]=INF; Vis[i]=0; Head[i]= -1; } k=0;}voidADD (intAintBintc) {NO[K].V=b; No[k].flow=C; No[k].next=Head[a]; Head[a]= k++;}voidSPFA (intd[]) {    intV, I, u; Queue<int>p; Q.push (1); d[1] =0;  while(!Q.empty ()) {v=Q.front ();        Q.pop ();  for(i = head[v]; I! =-1; i =No[i].next) {u=no[i].v; if(D[u] > d[v]+No[i].flow) {D[u]= d[v]+No[i].flow; if(!Vis[u])                    {Q.push (U); Vis[u]=1; }}} Vis[v]=0; }}intMain () {intT, M, I; Long Longans; scanf ("%d", &T);  while(t--) {scanf ("%d%d", &n, &m);        Init (D1); Ans=0;  for(i =1; I <= m; i++) {scanf ("%d%d%d", &AMP;MO[I].A, &mo[i].b, &mo[i].c); ADD (MO[I].A, mo[i].b, mo[i].c); ///first deposit in the direction, calculate the shortest path of 1 to other points} SPFA (D1); Init (D2); ///back-up after initialization, calculates the shortest path from 1 to other points         for(i =1; I <= m; i++) Add (mo[i].b, MO[I].A, mo[i].c);        SPFA (D2);  for(i =1; I <= N; i++) ans+ = d1[i]+D2[i]; printf ("%lld\n", ans); }    return 0;}

POJ 1511 Invitation Cards

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.