• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj3469

            Dual Core CPU

            Time Limit: 15000MS Memory Limit: 131072K
            Total Submissions: 12960 Accepted: 5553
            Case Time Limit: 5000MS

            Description

            As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.

            The routine consists of N modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let's define them as Ai and Bi. Meanwhile, M pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.

            Input

            There are two integers in the first line of input data, N and M (1 ≤ N ≤ 20000, 1 ≤ M ≤ 200000) .
            The next N lines, each contains two integer, Ai and Bi.
            In the following M lines, each contains three integers: a, b, w. The meaning is that if module a and module b don't execute on the same core, you should pay extra w dollars for the data-exchange between them.

            Output

            Output only one integer, the minimum total cost.

            Sample Input

            3 1
            1 10
            2 10
            10 3
            2 3 1000
            

            Sample Output

            13
            這題點(diǎn)有20000,邊有200000,所以要寫鏈表或者數(shù)組模擬
            終于找了個(gè)能看懂的了
            而且我覺著這代碼特別神有幾個(gè)地方
              1#include<stdio.h>
              2#include<string.h>
              3#include<math.h>
              4#define nmax 20010
              5#define emax 200010
              6#define inf 1<<30
              7int nn;
              8int head[nmax];
              9struct node
             10{
             11    int v,next,w;
             12}
            ;
             13struct node edge[emax*8];
             14int cnt,n,m,s,t;
             15void add(int u,int v,int w)
             16{
             17    edge[cnt].v=v;
             18    edge[cnt].w=w;
             19    edge[cnt].next=head[u];
             20    head[u]=cnt++;
             21    edge[cnt].v=u;
             22    edge[cnt].w=0;
             23    edge[cnt].next=head[v];
             24    head[v]=cnt++;
             25}

             26int sap()
             27{
             28    int pre[nmax],cur[nmax],dis[nmax],gap[nmax];
             29    int flow,aug,u;
             30    int flag;
             31    int i;
             32    flow=0;
             33    aug=inf;
             34    for(i=0; i<=nn; i++)
             35    {
             36        cur[i]=head[i];
             37        gap[i]=0;
             38        dis[i]=0;
             39    }

             40    gap[s]=nn;
             41    u=s;
             42    pre[s]=s;
             43    while(dis[s]<nn)
             44    {
             45        flag=0;
             46        for(int &j=cur[u]; j!=-1; j=edge[j].next)
             47        {
             48            int v=edge[j].v;
             49            if(edge[j].w>0&&dis[u]==dis[v]+1)
             50            {
             51                flag=1;
             52                if(edge[j].w<aug)aug=edge[j].w;
             53                pre[v]=u;
             54                u=v;
             55                if (u==t)
             56                {
             57                    flow+=aug;
             58                    while(u!=s)
             59                    {
             60                        u=pre[u];
             61                        edge[cur[u]].w-=aug;
             62                        edge[cur[u]^1].w+=aug;
             63                        //why?解釋偶數(shù)異或1為偶數(shù)+1,奇數(shù)異或1為奇數(shù)-1,
             64                        //顯然我們存的邊是從0開始存的,
             65                        //所以偶數(shù),偶數(shù)+1是殘量網(wǎng)格中的兩條邊(無向邊)
             66                    }

             67                    aug=inf;
             68                }

             69                break;
             70            }

             71        }

             72        if (flag) continue;
             73        int mindis=nn;
             74        for(int j=head[u];j!=-1;j=edge[j].next)
             75        {
             76            int v=edge[j].v;
             77            if (edge[j].w>0&&dis[v]<mindis)
             78            {
             79                mindis=dis[v];
             80                cur[u]=j;
             81            }

             82        }

             83        if (--gap[dis[u]]==0)//間隙優(yōu)化
             84        {
             85            break;
             86        }

             87        dis[u]=mindis+1;
             88        gap[dis[u]]++;
             89        u=pre[u];
             90    }

             91    return flow;
             92}

             93int main()
             94{
             95    int a,b,c,i;
             96    int ans;
             97    while (scanf("%d%d",&n,&m)!=EOF)
             98    {
             99        s=0;
            100        t=n+1;
            101        cnt=0;
            102        memset(head,-1,sizeof(head));
            103        for(i=1; i<=n; i++)
            104        {
            105            scanf("%d%d",&a,&b);
            106            add(s,i,a);
            107            add(i,t,b);
            108        }

            109        for(i=1; i<=m; i++)
            110        {
            111            scanf("%d%d%d",&a,&b,&c);
            112            add(a,b,c);
            113            add(b,a,c);
            114        }

            115        ans=0;
            116        nn=n+2;
            117        ans=sap();
            118        printf("%d\n",ans);
            119    }

            120    return 0;
            121}

            122

            有兩個(gè)需要特別注意的循環(huán)撒
            那個(gè)int j那個(gè)很奇怪,怪我語言沒學(xué)好
             

            posted on 2012-03-30 15:39 jh818012 閱讀(297) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            日韩人妻无码精品久久久不卡 | 女同久久| 国产成人久久777777| 91视频国产91久久久| 色婷婷综合久久久久中文一区二区| 香港aa三级久久三级老师2021国产三级精品三级在 | 丰满少妇人妻久久久久久| 久久香蕉超碰97国产精品| 麻豆成人久久精品二区三区免费| 国产成人久久精品一区二区三区| 婷婷国产天堂久久综合五月| 中文精品99久久国产| 久久成人国产精品免费软件| 久久久久亚洲精品天堂| 久久电影网2021| 久久久久综合国产欧美一区二区| 日批日出水久久亚洲精品tv| 亚洲精品97久久中文字幕无码| 久久中文字幕人妻熟av女| 亚洲综合日韩久久成人AV| 国产精品久久久久久久久免费 | 亚洲国产成人久久综合区| 成人午夜精品无码区久久| 久久精品国产亚洲精品2020| 国产日韩久久免费影院| 久久人人爽人人爽人人片AV麻烦| 久久青青草原亚洲av无码app| 国产精品99久久久久久董美香| 久久久久99这里有精品10 | 香蕉久久夜色精品国产2020| 99999久久久久久亚洲| 91久久香蕉国产熟女线看| 久久久久久久91精品免费观看| 久久久久久久综合日本亚洲| 香蕉久久夜色精品国产尤物| 久久99热精品| 久久婷婷国产综合精品| 午夜精品久久久久成人| 青青青青久久精品国产 | 久久久久亚洲av成人网人人软件| 国产精品无码久久综合|