HDU 1535 Invitation Cards (SPFA)

Source: Internet
Author: User

Invitation Cardstime limit:10000/5000ms (java/other) Memory limit:65536/65536k (java/other) Total Submission (s): 28 Accepted Submission (s): 14font:times New Roman | Verdana | Georgiafont Size:←→problem DescriptionIn 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.

Inputthe 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. Outputfor each case, print one line containing the minimum amount of money to is paid each day by ACM for the travel costs of its 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

/*This question has been memory limit exceeded open variable is too big, and then open a vector<node> s; it's not going to work. three int type [1000002] array can be in short, the container cannot use too much ... */#include<iostream>#include<cstdio>#include<vector>#include<cstring>#include<queue>using namespacestd;BOOLvis[1000002];structnode{intnum,d; Node (intAintb) {num=a; d=b;}}; Vector<node> s[1000002];intdis[1000002];inti,j,n,m,t;Const intinf=0x7fffffff;intx[1000002],y[1000002],d[1000002];voidSPFA () {inti,j;  for(i=1; i<=n;i++) {dis[i]=inf;vis[i]=0;} vis[1]=1; dis[1]=0; Queue<int>p; Q.push (1);  while(!Q.empty ()) {        intp=Q.front ();        Q.pop (); VIS[P]=0;  for(i=0; I<s[p].size (); i++)        {            if(DIS[S[P][I].NUM]&LT;=DIS[P]+S[P][I].D)Continue; Dis[s[p][i].num]=dis[p]+S[P][I].D; if(!Vis[s[p][i].num])                {Q.push (s[p][i].num); Vis[s[p][i].num]=1; }        }    }    return;}intMain () {scanf ("%d",&t);  for(;t>0; t--) {scanf ("%d%d",&n,&m);  for(i=1; i<=n;i++) s[i].clear ();  for(i=1; i<=m;i++) {scanf ("%d%d%d",&x[i],&y[i],&D[i]);        S[x[i]].push_back (Node (y[i],d[i)); }        intsum=0;        SPFA ();  for(i=2; i<=n;i++) sum+=Dis[i];  for(i=1; i<=n;i++) s[i].clear ();  for(i=1; i<=m;i++) S[y[i]].push_back (node (x[i],d[i));        SPFA ();  for(i=2; i<=n;i++) sum+=Dis[i]; printf ("%d\n", sum); }    return 0;}

HDU 1535 Invitation Cards (SPFA)

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.