• <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>

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語默心酸。二十光陰無一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            ZOJ 3378 Attack the NEET Princess 求無向圖任意兩點(diǎn)之間的割邊

               所謂0->n-1路徑上一定要經(jīng)過的割邊,就是0->n-1任意一條路徑上的割邊,因?yàn)楦钸吺潜亟?jīng)之路。其實(shí)這題跟ZOJ 2588是同一個(gè)題,稍微變化就可以得到答案了,不過這題我當(dāng)時(shí)的模板貌似寫挫了,對(duì)邊進(jìn)行判重的時(shí)候進(jìn)行了暴力,其實(shí)可以用set存一下,那么查找的復(fù)雜度可以降到log(n).
             具體求割邊的方法可以看這個(gè):http://www.shnenglu.com/abilitytao/archive/2009/09/26/97267.html
            不過程序貌似有問題,代碼寫得比較挫,就不值得借鑒了。
            #include<iostream>
            #include
            <algorithm>
            #include
            <set>
            #include
            <cstdio>
            #include
            <memory.h>
            using namespace std;
            #define min(a,b) ((a<b?a:b))

            set<int>mm;//存儲(chǔ)重邊

            int const maxn=10010;//頂點(diǎn)數(shù)
            int const maxm=100010;//邊數(shù)
            int n,m;

            struct Edge
            {
                
            int u,v,idx;
                
            bool operator<(Edge o)const
                
            {
                    
            if(u!=o.u)
                        
            return u<o.u;
                    
            else
                        
            return v<o.v;
                }

            }
            e[maxm*2];

            struct node
            {
                
            int t;
                
            int idx;
                node 
            *next;
            }
            edge[maxm*2];

            node 
            *adj[maxn];
            int len=0;


            void addedge(int u,int v,int idx)//加入一條邊
            {
                edge[len].idx
            =idx;edge[len].next=adj[u];edge[len].t=v;adj[u]=&edge[len++];
            }




            void input()
            {
                
            int i;
                
            for(i=0;i<m;i++)
                
            {
                    scanf(
            "%d%d",&e[i].u,&e[i].v);
                    e[i].idx
            =i;
                    
            if(e[i].u>e[i].v)
                        swap(e[i].u,e[i].v);
                }

                sort(e,e
            +m);
                
            int flag=0;
                
            for(i=0;i<m-1;i++)
                
            {

                    
            if(e[i].u!=e[i+1].u||e[i].v!=e[i+1].v)
                    
            {

                        addedge(e[i].u,e[i].v,e[i].idx);
                        addedge(e[i].v,e[i].u,e[i].idx);

                        
            if(flag==1)
                        
            {
                            mm.insert(e[i].idx);
                            flag
            =0;
                        }



                    }

                    
            else 
                    
            {
                        flag
            =1;
                        mm.insert(e[i].idx);
                    }


                }

                addedge(e[m
            -1].u,e[m-1].v,e[m-1].idx);
                addedge(e[m
            -1].v,e[m-1].u,e[m-1].idx);
                
            if(flag==1)
                    mm.insert(e[m
            -1].idx);


            }


            int v[maxn];
            int dfsn[maxn];//時(shí)間戳
            int low[maxn];//記錄它和它的子孫結(jié)點(diǎn)能夠到達(dá)的最小時(shí)間戳
            int re[maxm*2];
            int nAns;//記錄結(jié)果數(shù)目
            int T=0;

            void init(int n)
            {
                mm.clear();
                nAns
            =0;
                
            int i;
                
            for(i=0;i<=n;i++)
                    adj[i]
            =NULL;
                len
            =0;
            }


            void dfs(int fa,int x)//傳入樹的父親結(jié)點(diǎn)
            {
                v[x]
            =1;dfsn[x]=T;low[x]=T;T++;
                node 
            *p;
                
            for(p=adj[x];p!=NULL;p=p->next)
                
            {
                    
            if(p->t==fa)
                        
            continue;
                    
            int u=p->t;
                    
            if(!v[u])
                    
            {
                        dfs(x,u);
                        low[x]
            =min(low[x],low[u]);//注意是low值相比較,畫個(gè)圖很好理解
                    }

                    
            else if(u!=x)
                        low[x]
            =min(dfsn[u],low[x]);
                }


            }




            int findAns=0;
            void DfsFindPath(int fa,int x)
            {
                v[x]
            =1;
                
            if(x==n-1)
                
            {
                    findAns
            =1;
                    
            return;
                }

                node 
            *p;
                
            for(p=adj[x];p!=NULL;p=p->next)
                
            {
                    
            if(!v[p->t])
                    
            {
                        DfsFindPath(x,p
            ->t);
                        
            if(findAns==1)
                        
            {
                            
            if(low[p->t]>dfsn[x])
                            
            {
                                
            if(mm.find(p->idx)==mm.end())
                                    re[nAns
            ++]=p->idx;
                            }

                            
            return;
                        }


                    }

                }

            }



            void FindBridge(int s)
            {
                T
            =0;
                nAns
            =0;
                memset(v,
            0,sizeof(v));
                findAns
            =0;
                dfs(
            -1,s);//注意第一個(gè)結(jié)點(diǎn)的父親用-1表示
                memset(v,0,sizeof(v));
                DfsFindPath(
            -1,s);

            }





            int main()
            {
                
            while(scanf("%d%d",&n,&m)!=EOF)
                
            {
                    init(n);
                    input();
                    FindBridge(
            0);
                    sort(re,re
            +nAns);
                    printf(
            "%d\n",nAns);
                    
            int i;
                    
            for(i=0;i<nAns;i++)
                    
            {
                        
            if(i>0)
                            printf(
            " ");
                        printf(
            "%d",re[i]);
                    }

                    printf(
            "\n");
                }


                
            return 0;
            }

            posted on 2010-08-24 23:41 abilitytao 閱讀(1493) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

            # re: ZOJ 3378 Attack the NEET Princess 求無向圖任意兩點(diǎn)之間的割邊 2010-08-29 17:54 Tanky Woo

            朋友你好:
            C/C++和算法論壇:C++奮斗樂園
            歡迎你加入。
            里面有C/C++交流,求助,源碼,
            算法學(xué)習(xí),求助,
            ACM刷題
            等各種板塊,
            相信大家在一起能學(xué)習(xí)快樂。

            論壇地址:
            [url=http://www.cppleyuan.com/index.php]http://www.cppleyuan.com/index.php[/url]

            另外,論壇現(xiàn)在招收版主,有意愿的朋友可以看看:
            [url=http://www.cppleyuan.com/forumdisplay.php?fid=44]http://www.cppleyuan.com/forumdisplay.php?fid=44[/url]

            注:此留言絕不是廣告,只是看見博主也是C/C++和算法的愛好者,我們想邀請(qǐng)博主一起加入我們的 論壇。

            我也是一名C/C++和ACM愛好者,大家可以去我博客看看就知道了:
            [url=http://www.wutianqi.com/]http://www.wutianqi.com/[/url]

            打擾之處請(qǐng)見諒。
              回復(fù)  更多評(píng)論   


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


            国产免费久久精品丫丫| 久久亚洲精品视频| 国产精品免费看久久久| 久久夜色精品国产噜噜亚洲AV| 欧美久久久久久精选9999| 久久人人爽人人爽人人AV东京热 | 久久久久高潮毛片免费全部播放| 蜜桃麻豆www久久国产精品| 88久久精品无码一区二区毛片| 久久久久久久久久久久中文字幕| 久久精品亚洲日本波多野结衣| 久久精品毛片免费观看| …久久精品99久久香蕉国产| 久久精品一区二区| 久久久久亚洲AV无码专区桃色| 免费国产99久久久香蕉| 亚洲国产成人久久笫一页| 日韩一区二区久久久久久 | 久久精品国产亚洲av水果派| 久久精品亚洲日本波多野结衣| 青春久久| 久久国产精品成人影院| 亚洲国产精品久久久久婷婷软件 | 99久久777色| 色天使久久综合网天天| 国产精品一区二区久久精品无码| 色偷偷久久一区二区三区| 久久精品成人| 国产精品欧美久久久久无广告| 久久综合香蕉国产蜜臀AV| 2021久久精品免费观看| 一本一道久久a久久精品综合 | 国产亚洲精品美女久久久| 中文字幕无码精品亚洲资源网久久| 久久伊人五月天论坛| 久久精品夜色噜噜亚洲A∨| 国产精品久久久久乳精品爆 | 青青青青久久精品国产| 狠狠色丁香久久综合婷婷| 97久久超碰成人精品网站| 国产一级做a爰片久久毛片|