Usaco-4.1-fence6-passed

Source: Internet
Author: User

Oh, how can this happen?

/*ID: qq104801LANG: C++TASK: fence6*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <queue>#include <stack>#include <algorithm>using namespace std;const int INF=1<<25;const int nmax=200;static int n,a[nmax][nmax],d[nmax][nmax];static int len[nmax],le[nmax][nmax],rig[nmax][nmax];static int s,ans;void test(){        freopen("fence6.in","r",stdin);    freopen("fence6.out","w",stdout);      //init readin and change    cin>>n;    for(int i=1;i<=n;i++)        for(int j=1;j<=n;j++)a[i][j]=INF;        for(int i=1;i<=n;i++)    {        cin>>s;        cin>>len[s]>>le[s][0]>>rig[s][0];        for(int j=1;j<=le[s][0];j++)cin>>le[s][j];        for(int j=1;j<=rig[s][0];j++)cin>>rig[s][j];    }        for(int i=1;i<=n;i++)    {        for(int j=1;j<=le[i][0];j++)a[i][le[i][j]]=len[i]+len[le[i][j]];        for(int j=1;j<=rig[i][0];j++)a[i][rig[i][j]]=len[i]+len[rig[i][j]];    }    for(int i=1;i<=n;i++)        for(int j=1;j<=n;j++)d[i][j]=a[i][j];    //work Floyd    ans=1<<30;    for(int k=1;k<=n;k++)    {        for(int i=1;i<=le[k][0];i++)        {            int ii=le[k][i];            if(ii<k)            {                for(int j=1;j<=rig[k][0];j++)                {                    int jj=rig[k][j];                    if(jj<k)                        ans=min(ans,a[ii][jj]+d[k][ii]+d[k][jj]);                }            }        }        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)                a[i][j]=min(a[i][j],a[i][k]+a[k][j]);    }    cout<<ans/2<<endl;}int main () {            test();            return 0;}

Test data:

USACO TrainingGrader Results     13 users onlineBGD/1 CHN/4 USA/8USER: cn tom [qq104801]TASK: fence6LANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.008 secs, 4000 KB]   Test 2: TEST OK [0.008 secs, 4000 KB]   Test 3: TEST OK [0.005 secs, 4000 KB]   Test 4: TEST OK [0.005 secs, 4000 KB]   Test 5: TEST OK [0.005 secs, 4000 KB]   Test 6: TEST OK [0.011 secs, 4000 KB]   Test 7: TEST OK [0.005 secs, 4000 KB]   Test 8: TEST OK [0.005 secs, 4000 KB]   Test 9: TEST OK [0.022 secs, 4000 KB]All tests OK.YOUR PROGRAM (‘fence6‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.Here are the test data inputs:------- test 1 ----101 16 2 22 710 62 3 2 21 78 33 3 2 18 244 8 1 339 10 55 8 3 19 10 466 6 1 251 107 5 2 21 28 98 4 2 22 37 99 5 2 37 84 5 1010 10 2 31 64 9 5------- test 2 ----31 1 1 1232 1 1 1313 1 1 112------- test 3 ----61 3 2 22 36 53 3 2 21 24 55 5 2 23 46 12 3 2 26 41 34 5 2 23 52 66 5 2 21 54 2------- test 4 ----121 100 1 223 42 99 1 1313 101 1 221 44 3 2 25 71 35 76 2 17 466 75 1 258 97 77 2 15 488 74 1 276 99 4 2 210 126 810 102 2 112 91111 100 1 1101212 101 1 2119 10------- test 5 ----121 24 1 7210 9 12 3 4 6 72 37 1 1133 214 1 721 10 9 12 4 6 74 83 1 751 10 9 3 12 6 75 247 1 1466 10 1 751 10 3 12 4 7 97 15 1 781 10 3 12 4 6 98 73 1 1799 135 1 781 10 3 12 4 6 710 42 1 7111 3 12 4 6 7 911 191 1 1101212 85 1 71110 1 3 4 6 7 9------- test 6 ----141 1 1 11424 1 1 15313 1 1 1141214 1 1 11319 2 1 2610 87 14 2 15 6811 1 1 112102 1 1 11310 1 1 2119 88 23 2 110 973 1 1 1246 2 2 15 795 1 1 246 712 1 1 11311------- test 7 ----3116 10 2 22 1517 181 80 1 1232 80 1 2115 164 80 2 23 58 95 200 2 13 4721 80 1 21820 2222 80 2 220 2123 276 160 2 29 107 147 80 1 256 148 10 2 14 91517 10 2 116 18199 10 2 24 86 1010 10 2 19 61111 10 1 21029 1214 80 2 16 71315 10 2 12 16818 80 2 116 172130 10 2 219 2024 2319 10 1 21720 3020 80 2 219 3021 2223 80 2 222 2730 2412 80 2 211 2913 2613 80 1 21412 2624 10 2 123 303125 80 2 227 2831 2926 80 2 112 132827 80 2 222 2325 2828 80 2 127 25263 80 1 214 529 10 2 211 1231 2531 10 1 22429 25------- test 8 ----1001 8 1 110022 8 1 1133 8 1 1244 8 1 1355 8 1 1466 8 1 1577 8 1 1688 8 1 1799 8 1 181010 8 1 191111 8 1 1101212 8 1 1111313 8 1 1121414 8 1 1131515 8 1 1141616 8 1 1151717 8 1 1161818 8 1 1171919 8 1 1182020 8 1 1192121 8 1 1202222 8 1 1212323 8 1 1222424 8 1 1232525 8 1 1242626 8 1 1252727 8 1 1262828 8 1 1272929 8 1 1283030 8 1 1293131 8 1 1303232 8 1 1313333 8 1 1323434 8 1 1333535 8 1 1343636 8 1 1353737 8 1 1363838 8 1 1373939 8 1 1384040 8 1 1394141 8 1 1404242 8 1 1414343 8 1 1424444 8 1 1434545 8 1 1444646 8 1 1454747 8 1 1464848 8 1 1474949 8 1 1485050 8 1 1495151 8 1 1505252 8 1 1515353 8 1 1525454 8 1 1535555 8 1 1545656 8 1 1555757 8 1 1565858 8 1 1575959 8 1 1586060 8 1 1596161 8 1 1606262 8 1 1616363 8 1 1626464 8 1 1636565 8 1 1646666 8 1 1656767 8 1 1666868 8 1 1676969 8 1 1687070 8 1 1697171 8 1 1707272 8 1 1717373 8 1 1727474 8 1 1737575 8 1 1747676 8 1 1757777 8 1 1767878 8 1 1777979 8 1 1788080 8 1 1798181 8 1 1808282 8 1 1818383 8 1 1828484 8 1 1838585 8 1 1848686 8 1 1858787 8 1 1868888 8 1 1878989 8 1 1889090 8 1 1899191 8 1 1909292 8 1 1919393 8 1 1929494 8 1 1939595 8 1 1949696 8 1 1959797 8 1 1969898 8 1 1979999 8 1 198100100 8 1 1991------- test 9 ----931 25 2 190 9322 25 1 1133 25 1 1244 25 1 1355 25 1 1466 25 1 1577 25 1 1688 25 1 1799 25 1 181010 25 1 191111 25 1 1101212 25 1 1111313 25 1 1121414 25 1 1131515 25 1 1141616 25 1 1151717 25 1 1161818 25 1 1171919 25 1 1182020 25 1 1192121 25 1 1202222 25 1 1212323 25 1 1222424 25 1 1232525 25 1 1242626 25 1 1252727 25 1 1262828 25 1 1272929 25 1 1283030 25 1 22931 9131 25 2 130 913232 25 1 1313333 25 1 1323434 25 1 1333535 25 1 1343636 25 1 1353737 25 1 1363838 25 1 1373939 25 1 1384040 25 1 1394141 25 1 1404242 25 1 1414343 25 1 1424444 25 1 1434545 25 1 1444646 25 1 1454747 25 1 1464848 25 1 1474949 25 1 1485050 25 1 1495151 25 1 1505252 25 1 1515353 25 1 1525454 25 1 1535555 25 1 1545656 25 1 1555757 25 1 1565858 25 1 1575959 25 1 1586060 25 1 25961 9261 25 2 160 926262 25 1 1616363 25 1 1626464 25 1 1636565 25 1 1646666 25 1 1656767 25 1 1666868 25 1 1676969 25 1 1687070 25 1 1697171 25 1 1707272 25 1 1717373 25 1 1727474 25 1 1737575 25 1 1747676 25 1 1757777 25 1 1767878 25 1 1777979 25 1 1788080 25 1 1798181 25 1 1808282 25 1 1818383 25 1 1828484 25 1 1838585 25 1 1848686 25 1 1858787 25 1 1868888 25 1 1878989 25 1 1889090 25 1 2891 9393 250 2 21 9092 9191 250 2 292 9330 3192 250 2 291 9361 60Keep up the good work!Thanks for your submission!
View code

 

Usaco-4.1-fence6-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.