Usaco-4.1-ditch-passed

Source: Internet
Author: User

This pitfall project is indeed pitfall.

/*ID: qq104801LANG: C++TASK: ditch*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <queue>#include <stack>#include <algorithm>using namespace std;const int inf=0xfffffff;const int nmax=205;int n,m,ans;int a[nmax][nmax];int next[nmax],d[nmax][nmax],p[nmax];queue<int>q;void test(){        freopen("ditch.in","r",stdin);    freopen("ditch.out","w",stdout);      //init readin and change    cin>>n>>m;    int k1,k2,k3;    for(int i=1;i<=n;i++)    {        cin>>k1>>k2>>k3;        a[k1][k2]+=k3;    }    while(true)    {        memset(p,0,sizeof(p));        p[1]=inf;        q.push(1);        while(!q.empty())        {            int v=q.front();q.pop();            for(int i=1;i<=m;i++)                if(!p[i] && a[v][i]>d[v][i])                {                    next[i]=v;q.push(i);                    p[i]=p[v]<a[v][i]-d[v][i]?p[v]:a[v][i]-d[v][i];                                    }        }        if(!p[m])break;        for(int i=m;i!=1;i=next[i])        {            d[next[i]][i]+=p[m];            d[i][next[i]]-=p[m];        }        ans+=p[m];    }    cout<<ans<<endl; }int main () {            test();            return 0;}

Test Data

USACO TrainingGrader Results     8 users onlineCHN/5 IRN/1 POL/1 USA/1USER: cn tom [qq104801]TASK: ditchLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.008 secs, 3836 KB]   Test 2: TEST OK [0.005 secs, 3836 KB]   Test 3: TEST OK [0.005 secs, 3836 KB]   Test 4: TEST OK [0.008 secs, 3836 KB]   Test 5: TEST OK [0.005 secs, 3836 KB]   Test 6: TEST OK [0.008 secs, 3836 KB]   Test 7: TEST OK [0.008 secs, 3836 KB]   Test 8: TEST OK [0.016 secs, 3836 KB]   Test 9: TEST OK [0.014 secs, 3836 KB]   Test 10: TEST OK [0.005 secs, 3836 KB]   Test 11: TEST OK [0.008 secs, 3836 KB]   Test 12: TEST OK [0.011 secs, 3836 KB]All tests OK.YOUR PROGRAM (‘ditch‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----5 41 2 401 4 202 4 202 3 303 4 10------- test 2 ----3 31 2 52 2 1002 3 3------- test 3 ----7 61 2 100002 3 100003 6 100001 4 80004 3 80002 5 60005 6 6000------- test 4 ----13 51 2 461 3 731 4 331 5 202 3 352 4 152 5 863 2 513 4 933 5 354 2 1004 3 914 5 11------- test 5 ----22 111 6 51 7 31 3 56 3 23 7 26 4 36 5 23 5 53 9 27 9 39 5 15 4 14 10 55 10 25 2 35 8 29 8 310 2 22 8 210 11 52 11 48 11 4------- test 6 ----18 121 3 71 2 33 6 13 5 22 6 32 5 32 4 36 9 45 9 25 8 45 7 24 7 37 10 39 11 38 11 28 10 210 12 311 12 4------- test 7 ----150 501 20 103591 11 88415611 4 38258020 30 6437644 35 1082624 31 596430 45 3900020 28 6849045 34 21080131 10 30829520 6 13873620 42 74693834 16 85207831 38 2777486 46 1869630 40 41758234 7 8803828 44 69454411 29 31731211 13 5558396 17 188031 39 5962442 41 792406 33 20797520 18 26256042 14 24771816 36 12180641 23 10987233 48 12478639 2 11700820 49 38217644 47 72639 9 13764823 21 2778759 15 30990230 8 5460033 12 20120833 32 90730836 24 26103046 27 11739618 22 81846038 19 56736132 5 4836451 26 31931018 3 14337633 25 33569240 37 18825831 43 48314028 50 11196735 48 37219349 43 4912005 31 24869211 9 5174395 25 1320011 10 742913 43 47514647 48 31186518 29 20300833 22 12654035 38 1103078 22 74505628 42 57590016 50 29286432 17 47677934 29 39026042 16 34776114 34 34752949 21 23895215 12 988239 20 57792011 27 8743242 29 38932543 45 4787840 30 7433334 39 40968437 1 70882549 34 7921623 23 12091527 30 2391697 18 132447 6 59966445 23 3422415 5 30074836 33 4943849 3 3735613 43 18420024 6 66500042 7 6099832 30 7778743 31 57422 9 34083040 6 3492012 41 33858843 10 38718034 11 35925117 48 4982325 42 54092520 24 14871617 34 54615042 41 4108009 28 4854753 33 22552419 8 22663447 30 16329635 27 40668613 4 2714679 22 34138836 41 37977624 50 84835030 6 38637917 16 3525217 23 56898012 26 512413 4 1515256 23 58962019 43 552967 3 18293215 4 10472040 15 49602715 30 2550849 38 8733010 42 3771698 45 33185037 16 35994037 41 367682 36 40047632 41 80396447 35 14916939 20 1452047 19 2613045 1 1984042 13 22536818 24 14169631 44 1407608 38 59919628 9 23784647 36 30132521 18 2754623 17 20811034 17 26371831 20 37216449 2 49816811 7 32391234 2 10225620 10 20716525 3 7164923 21 15611216 48 84033 8 1010524 18 39879------- test 8 ----183 151 2 311 3 461 4 261 5 291 6 621 7 251 8 381 9 71 10 391 11 311 12 861 13 921 14 501 15 92 3 432 4 882 5 302 6 142 7 442 8 872 9 682 10 652 11 162 12 682 13 652 14 422 15 23 2 183 4 563 5 493 6 283 7 43 8 443 9 823 10 763 11 703 12 673 13 933 14 193 15 764 2 514 3 54 5 844 6 474 7 634 8 724 9 914 10 654 11 144 12 284 13 444 14 664 15 365 2 275 3 115 4 705 6 745 7 185 8 825 9 145 10 255 11 525 12 295 13 55 14 635 15 646 2 606 3 756 4 656 5 436 7 56 8 496 9 76 10 66 11 66 12 96 13 296 14 116 15 567 2 627 3 287 4 267 5 667 6 1007 8 977 9 587 10 27 11 617 12 637 13 77 14 637 15 668 2 328 3 118 4 438 5 638 6 28 7 548 9 688 10 308 11 648 12 238 13 288 14 878 15 279 2 669 3 929 4 549 5 999 6 369 7 559 8 179 10 729 11 889 12 779 13 339 14 249 15 410 2 7110 3 3310 4 9410 5 1210 6 910 7 5910 8 4110 9 8210 11 8910 12 9810 13 5310 14 5010 15 4211 2 3811 3 10011 4 7411 5 1911 6 1411 7 811 8 5811 9 3511 10 7711 12 5211 13 4611 14 1011 15 3512 2 2712 3 3512 4 9412 5 2712 6 1612 7 9912 8 112 9 4512 10 212 11 7712 13 4012 14 9512 15 4713 2 1013 3 9013 4 9913 5 8413 6 9513 7 7813 8 1713 9 3513 10 2613 11 1613 12 2413 14 2813 15 9614 2 8014 3 8714 4 9814 5 3214 6 4614 7 8814 8 5214 9 2914 10 9114 11 5514 12 9914 13 7014 15 81------- test 9 ----199 2001 77 6048841 158 448277 160 333909158 72 830172160 64 11130072 40 939677 10 6507040 125 76048777 20 22372810 90 559854160 82 2368420 190 1995140 89 23091772 163 496531163 81 27311210 67 37939282 79 3554261 9 51578864 55 33877672 166 22371079 189 4292140 156 15570964 104 43155079 177 68477767 129 55872166 76 13373481 186 50321182 172 4704076 145 37416166 115 49680129 137 55126555 174 37367267 7 208311160 32 1846001 194 5887190 131 600576174 86 45660125 83 298622115 3 208636189 38 8716564 134 13939129 120 8345619 114 87335683 61 241411125 21 945132 121 582826114 42 410101 122 7052210 193 102916137 182 15022864 123 42257686 78 1380089 58 32263114 52 275138182 144 30408358 43 442677166 93 83928943 98 16200061 154 9544843 181 3796189 16 315746125 80 19133389 139 326648129 60 23580061 45 127610172 180 193669156 70 131008104 185 30435861 6 13812479 34 65310320 183 153560158 48 12577580 184 684530166 41 15080048 5 504546145 35 5599121 8 44550160 178 8800883 192 19775098 171 41985661 74 498050174 124 9180077 109 14244382 71 14788798 36 1415558 151 324319 69 458736193 11 676788124 31 228613185 191 250010185 14 37402681 23 7138008 91 46172109 197 23111498 73 726792194 62 130084129 138 4062131 13 27485069 15 2410861 155 15925192 111 55874261 29 232392158 118 21089673 28 170820111 135 229704137 132 149916194 126 270359123 37 17604138 168 265972137 88 200238132 2 14654482 187 75690172 27 57529621 65 80870482 63 154890137 101 24156914 102 180495109 22 670140191 44 12962838 107 42642028 39 11404240 164 951500180 153 64190420 49 13395149 173 238822109 148 2248098 50 56724844 105 24590093 133 12998436 116 129008178 54 30753183 188 29890194 167 453888135 18 314336144 108 35134835 141 7286410 66 10641616 51 116171125 157 53204178 92 8551916 53 2607662 195 37212292 19 434115197 196 15216369 30 179488174 25 7975687 103 1687952 176 40303249 17 30466893 12 1708193 198 51123698 146 29059831 179 78883240 117 29106738 100 40735523 96 467181183 46 442224144 161 675613 136 13240171 127 27824030 47 92040137 33 327921132 95 22870493 175 2858014 113 289170154 4 74911262 152 827836146 57 5737619 87 15072179 24 26052126 143 135582154 128 10936866 75 26183891 110 97314103 68 1656015 170 52828170 84 19250125 159 33300129 199 4818874 112 15248214 130 216112185 59 603099127 162 38488844 85 264600137 99 16003855 169 5872036 147 141354163 26 3272625 142 185472129 150 247764105 106 25193158 119 98928130 94 36069033 149 43442031 165 57198065 140 175080163 56 9010338 97 35158 200 633027------- test 10 ----199 501 46 2501041 24 8992621 15 800551 37 506031 49 3780037 38 32087037 6 8681115 2 222441 45 18137349 7 354415 12 40360446 8 69072037 28 2634121 40 7137012 48 284048 21 732615 43 33231012 11 69022821 27 7522546 3 4429502 25 29796015 4 26746745 5 1343212 35 14149227 23 2156003 34 36960037 9 490512 14 30074414 19 36404027 20 38239649 10 6418232 41 811539 32 1675105 44 2712194 16 1118423 29 27550211 42 43207814 18 1696548 33 27345623 39 13938440 31 975674 26 18824616 47 1389808 22 17257733 36 1112307 30 210543 17 411815 13 52885829 50 24076043 47 27751436 41 84250613 33 18645634 9 2140343 45 45982525 37 33647424 17 14120011 50 51353534 17 50467236 7 480233 36 86782523 46 43808033 38 47242827 37 1372004 14 1276840 38 5596472 48 7385687 14 16438839 29 20050635 1 19752433 30 146632 43 4724426 34 14677222 14 3753964 23 36216849 17 15501627 22 2316605 25 36758411 44 78156839 36 35648122 50 59730014 27 816819 5 579612 24 10714110 2 34808 20 138705 31 53759146 50 68286441 12 3690014 31 38517646 32 43824038 44 27878423 33 2485520 37 12464023 17 5610043 19 221764 49 43424121 28 1379525 18 16156818 37 17619022 4 30967510 31 61954846 5 20679617 30 19555248 14 47907625 25 10074433 6 30891334 16 7025232 34 6009640 9 5831224 25 19980048 20 94097539 35 60443513 27 43785242 13 8249016 42 600301 16 69552022 29 54447925 34 34752915 28 5593025 22 7767017 44 33473012 34 17267638 33 64053342 18 2452329 49 13406739 13 5978439 45 45295647 5 15614415 35 6243440 40 6618522 4 7222044 38 93452 30 5290829 23 77579538 14 56115038 46 22104029 12 1229201 28 75444431 23 29757014 50 72915045 35 13316323 49 61830026 29 31269821 31 12742828 39 25964432 24 8457627 10 308127 1 12592830 27 46566023 4 19806611 35 5364007 22 76315225 29 3121846 27 19754716 37 17670033 20 4662943 22 4867831 28 79753444 30 48305528 9 14467628 49 17269226 15 27391648 27 7226749 8 10779316 37 64837547 35 45073028 11 9711838 8 12828041 17 1626421 42 736222 3 3822213 45 2554524 41 8794525 18 6417045 30 86589011 13 9136815 2 2945 39 50286027 42 20716234 37 64927240 3 79776017 46 67381614 37 17113340 41 39743243 26 20986020 13 3775783 22 12960240 16 11398230 46 32417024 14 22627840 37 58879538 38 5001515 10 143828 46 58560029 22 14448530 41 4101679 43 52218020 44 32896816 34 88950------- test 11 ----200 1001 4 170854 28 18922528 16 632884 2 75933016 62 4141782 36 3294404 95 5830201 69 19729836 80 82645480 27 11316980 68 4612836 96 31410096 3 14433062 85 60627685 32 53366428 24 2286833 23 4193836 41 2355122 81 18634880 77 67345616 94 5376028 47 11698780 56 233583 15 22623862 63 64190041 54 6710477 92 1808080 37 1821077 30 636002 93 52827 7 3061869 66 16467981 60 20443523 59 11392485 61 66723416 12 31456094 73 6054092 43 6486495 42 7867256 39 745054 31 38347496 8 37814460 21 13255077 45 50122832 34 1829639 83 69910077 74 42816831 78 57734877 44 36030885 72 21951680 25 24220868 38 39724444 84 33868896 76 9495227 64 45030032 51 12177095 79 6677464 82 42529584 90 4320481 65 15417574 40 2128072 26 3640076 18 3199473 46 13843784 98 1065092 70 21012054 11 14241028 10 10974066 14 33605093 35 28327266 48 14311848 58 67084259 75 579283 89 2356028 53 15096036 71 41285032 97 26754076 33 14267976 5 12496089 20 80107344 55 32236893 22 16713955 57 26726733 17 1665951 87 6758081 13 34584040 9 36887453 50 54684546 52 29016861 86 35990492 29 15811646 49 308476 19 2505237 6 33995777 88 25536080 67 61705681 91 19849610 99 69915262 100 5026868 33 8889283 70 52362539 28 35862049 80 24715074 4 61801797 42 48916 83 18369019 36 16264895 29 852051 94 66755473 63 1911622 49 2571589 37 407129 42 2348438 79 166420 93 51936039 92 47808068 36 2853633 21 46853479 15 82596886 80 19362997 43 15848410 43 4494459 25 13294079 98 222577 39 49485690 57 787292 86 572041 41 3264832 95 488154 13 1452533 99 1517046 89 17014874 64 10921421 93 9752482 89 11781968 95 21833736 67 51164895 93 28417189 98 170727 72 20620510 84 677462 15 41809525 66 51030031 82 7590084 40 50530066 51 13536631 23 90104874 20 4107685 91 44472613 74 30958248 73 19828833 8 4764707 13 44749296 22 64478761 87 4133765 73 15444056 90 4699540 88 27910532 83 23323223 44 25542485 100 49084273 7 5702239 21 33435696 34 5680032 4 73312570 41 75978213 85 3692549 28 12088854 32 25620085 71 59987475 72 74575253 73 43217473 70 25789092 81 44498876 81 2260967 62 7893514 52 3284424 46 19597534 100 8345477 25 26016095 42 6365722 22 34178465 92 49931033 15 58090373 23 10778783 30 28017832 84 38223079 93 16088168 87 63024093 45 21551472 53 5979586 20 8841659 20 62068263 85 16689740 16 10235570 42 48193210 90 9137768 95 44689644 14 5146548 77 101680------- test 12 ----0 2Keep up the good work!Thanks for your submission!
View code

 

Usaco-4.1-ditch-passed

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.