锘??xml version="1.0" encoding="utf-8" standalone="yes"?>麻豆精品传媒视频,亚洲一区制服诱惑,欧美日韩一区成人http://www.shnenglu.com/397993401/category/13854.html鍦ㄩ剻瑙嗕腑鎴愰暱 璁板綍鎴愰暱鐨勭偣婊?/description>zh-cnFri, 03 Sep 2010 01:28:58 GMTFri, 03 Sep 2010 01:28:58 GMT60hdu 1102 prim 鏈灝忕敓鎴愭爲http://www.shnenglu.com/397993401/archive/2010/09/02/125706.html浠樼繑浠樼繑Thu, 02 Sep 2010 15:48:00 GMThttp://www.shnenglu.com/397993401/archive/2010/09/02/125706.htmlhttp://www.shnenglu.com/397993401/comments/125706.htmlhttp://www.shnenglu.com/397993401/archive/2010/09/02/125706.html#Feedback0http://www.shnenglu.com/397993401/comments/commentRss/125706.htmlhttp://www.shnenglu.com/397993401/services/trackbacks/125706.htmlConstructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3780    Accepted Submission(s): 1298


Problem Description
There are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B, or there exists a village C such that there is a road between A and C, and C and B are connected. 

We know that there are already some roads between some villages and your job is the build some roads such that all the villages are connect and the length of all the roads built is minimum.
 

Input
The first line is an integer N (3 <= N <= 100), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 1000]) between village i and village j.

Then there is an integer Q (0 <= Q <= N * (N + 1) / 2). Then come Q lines, each line contains two integers a and b (1 <= a < b <= N), which means the road between village a and village b has been built.

Output
You should output a line contains an integer, which is the length of all the roads to be built such that all the villages are connected, and this value is minimum.


#include<iostream>
#include
<string.h>
using namespace std;

#define infinity 123456789
#define max_vertexes 100 

typedef 
int Graph[max_vertexes][max_vertexes];

Graph G;
int total;
int lowcost[max_vertexes],closeset[max_vertexes],used[max_vertexes];
int father[max_vertexes];
void prim(Graph G,int vcount)
{
    
int i,j,k;
    
int min = infinity;
    
for (i=0;i<vcount;i++)
    {
        lowcost[i]
=G[0][i];
        closeset[i]
=0
        used[i]
=0;
        father[i]
=-1
    }
    used[
0]=1
    
    
for (i=1;i<vcount;i++)
    {
        j
=0;
        
        
while (used[j]) j++;
        min 
= lowcost[j];
        
for (k=0;k<vcount;k++)
            
if ((!used[k])&&(lowcost[k]<min)) 
            {
                min 
=lowcost[k];
                j
=k;
            }
            father[j]
=closeset[j]; 
            used[j]
=1;
            total 
+= min;
            
for (k=0;k<vcount;k++)
                
if (!used[k]&&(G[j][k]<lowcost[k]))
                { 
                    lowcost[k]
=G[j][k];
                    closeset[k]
=j; 
                }
    }
}

int main()
{
    
int N,i,j,Q;
    
int x,y;
    
while(cin>>N)
    {
        
        total 
= 0;
        
for(i =0; i< N;i++)
        {
            
for(j = 0;j < N; j ++)
                cin
>>G[i][j];
        }
        cin
>>Q;
        
for(i = 0; i < Q; i ++)
        {
            cin
>>x>>y;
            G[x
-1][y-1= 0;
            G[y
-1][x-1= 0;
        }
        prim(G,N);
        cout
<< total<<endl;
    }
    
return 0;
}




浠樼繑 2010-09-02 23:48 鍙戣〃璇勮
]]>
鏈夊悜鍥懼己榪為氬垎閲?/title><link>http://www.shnenglu.com/397993401/archive/2010/05/20/115966.html</link><dc:creator>浠樼繑</dc:creator><author>浠樼繑</author><pubDate>Thu, 20 May 2010 12:28:00 GMT</pubDate><guid>http://www.shnenglu.com/397993401/archive/2010/05/20/115966.html</guid><wfw:comment>http://www.shnenglu.com/397993401/comments/115966.html</wfw:comment><comments>http://www.shnenglu.com/397993401/archive/2010/05/20/115966.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/397993401/comments/commentRss/115966.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/397993401/services/trackbacks/115966.html</trackback:ping><description><![CDATA[<h3 style="margin: 10px 0px 5px; font-family: sans-serif; font-style: normal; font-variant: normal; font-weight: bold; font-size: 170%; line-height: 100%; font-size-adjust: none; font-stretch: normal; color: #758d38;"> <p style="margin: 0px 0px 10px; padding: 0px; line-height: 22px;">杞嚜錛?/p> <p style="margin: 0px 0px 10px; padding: 0px; line-height: 22px;"><a style="line-height: 22px; text-decoration: none; color: #556c88;">http://www.byvoid.com/blog/scc-tarjan/ <br></a></p> <p style="margin: 0px 0px 10px; padding: 0px; line-height: 22px;"><a style="line-height: 22px; text-decoration: none; color: #556c88;"><br></a></p> <br><strong> </strong></h3> <h3 style="margin: 10px 0px 5px; font-family: sans-serif; font-style: normal; font-variant: normal; font-weight: bold; font-size: 170%; line-height: 100%; font-size-adjust: none; font-stretch: normal; color: #758d38;"><strong>[鏈夊悜鍥懼己榪為氬垎閲廬</strong> </h3> <p style="margin: 0px; padding: 0px 0px 15px;">鍦ㄦ湁鍚戝浘G涓紝濡傛灉涓や釜欏剁偣闂磋嚦灝戝瓨鍦ㄤ竴鏉¤礬寰勶紝縐頒袱涓《鐐?strong> 寮鴻繛閫?/strong> (strongly connected)銆傚鏋滄湁鍚戝浘G鐨勬瘡涓や釜欏剁偣閮藉己榪為氾紝縐癎鏄竴涓?strong> 寮鴻繛閫氬浘</strong> 銆傞潪寮鴻繛閫氬浘鏈夊悜鍥劇殑鏋佸ぇ寮鴻繛閫氬瓙鍥撅紝縐頒負<strong> 寮鴻繛閫氬垎閲?/strong> (strongly connected components)銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;">涓嬪浘涓紝瀛愬浘{1,2,3,4}涓轟竴涓己榪為氬垎閲忥紝鍥犱負欏剁偣1,2,3,4涓や袱鍙揪銆倇5},{6}涔熷垎鍒槸涓や釜寮鴻繛閫氬垎閲忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;"><img title="image" src="http://www.byvoid.com/blog/wp-content/uploads/2009/04/image1.png" alt="image" style="border-width: 0px; display: inline;" width="320" border="0" height="201"></p> <p style="margin: 0px; padding: 0px 0px 15px;">鐩存帴鏍規嵁瀹氫箟錛岀敤鍙屽悜閬嶅巻鍙栦氦闆嗙殑鏂規硶姹傚己榪為氬垎閲忥紝鏃墮棿澶嶆潅搴︿負O(N^2+M)銆傛洿濂界殑鏂規硶鏄疜osaraju綆楁硶鎴朤arjan綆楁硶錛屼袱鑰呯殑鏃墮棿澶嶆潅搴﹂兘鏄疧(N+M)銆傛湰鏂囦粙緇嶇殑鏄疶arjan綆楁硶銆?/p> <h3 style="margin: 10px 0px 5px; font-family: sans-serif; font-style: normal; font-variant: normal; font-weight: bold; font-size: 170%; line-height: 100%; font-size-adjust: none; font-stretch: normal; color: #758d38;"><strong> [Tarjan綆楁硶]</strong> </h3> <p style="margin: 0px; padding: 0px 0px 15px;">Tarjan綆楁硶鏄熀浜庡鍥炬繁搴︿紭鍏堟悳绱㈢殑綆楁硶錛屾瘡涓己榪為氬垎閲忎負鎼滅儲鏍戜腑鐨勪竴媯靛瓙鏍戙傛悳绱㈡椂錛屾妸褰撳墠鎼滅儲鏍戜腑鏈鐞嗙殑鑺傜偣鍔犲叆涓涓爢鏍堬紝鍥炴函鏃跺彲浠ュ垽鏂爤欏跺埌鏍堜腑鐨勮妭鐐規槸鍚︿負涓涓己榪為氬垎閲忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;">瀹氫箟DFN(u)涓鴻妭鐐箄鎼滅儲鐨勬搴忕紪鍙?鏃墮棿鎴?錛孡ow(u)涓簎鎴杣鐨勫瓙鏍戣兘澶熻拷婧埌鐨勬渶鏃╃殑鏍堜腑鑺傜偣鐨勬搴忓彿銆傜敱瀹氫箟鍙互寰楀嚭錛?/p> <div id="hvzpftn" class="wp_codebox_msgheader" style="border-width: 1px 1px 0px; border-top: 1px solid silver; border-left: 1px solid silver; border-right: 1px solid silver; margin: 0.5em 0px 0px; overflow: hidden; width: 671px; height: 22px; font-weight: bold; background-image: url(http://www.byvoid.com/blog/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: #f3f8d7; color: #000000; background-position: 100% 5px;"><sup><a target="_blank" title="WP-CodeBox howto?" style="color: #cc6600; text-decoration: none; font-family: Arial,Tahoma ! important; font-style: normal ! important; font-variant: normal ! important; font-weight: normal ! important; font-size: 14px ! important; line-height: normal ! important; font-size-adjust: none ! important; font-stretch: normal ! important;">?</a></sup><a href="javascript:;" onclick="javascript:showCodeTxt('p1235code1'); return false;" style="color: #cc6600; text-decoration: none; font-weight: bold;">View Code</a> CPP</div> <div id="hvzpftn" class="wp_codebox" style="border: 1px solid silver; margin: 0px 0px 0.5em; overflow: auto; color: #110000; width: 671px; background-color: #f9f9f9;"> <table style="margin: 0px ! important; border-collapse: collapse; width: 671px;"> <tbody> <tr id="p12351"> <td class="code" id="p1235code1" style="padding: 2px 4px; vertical-align: top;"> <pre class="cpp" style="border-style: none; margin: 0px; padding: 0px; overflow: visible; background-image: none; width: auto; float: none; clear: none; font-size: 12px; line-height: 1.333; text-align: left; font-family: monospace;">Low(u)=Min<br>{<br> DFN(u),<br> Low(v),(u,v)涓烘爲鏋濊竟錛寀涓簐鐨勭埗鑺傜偣<br> DFN(v),(u,v)涓烘寚鍚戞爤涓妭鐐圭殑鍚庡悜杈?闈炴í鍙夎竟)<br>}</pre> </td> </tr> </tbody> </table> </div> <p style="margin: 0px; padding: 0px 0px 15px;">褰揇FN(u)=Low(u)鏃訛紝浠涓烘牴鐨勬悳绱㈠瓙鏍戜笂鎵鏈夎妭鐐規槸涓涓己榪為氬垎閲忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;">綆楁硶浼唬鐮佸涓?/p> <div id="hvzpftn" class="wp_codebox_msgheader" style="border-width: 1px 1px 0px; border-top: 1px solid silver; border-left: 1px solid silver; border-right: 1px solid silver; margin: 0.5em 0px 0px; overflow: hidden; width: 671px; height: 22px; font-weight: bold; background-image: url(http://www.byvoid.com/blog/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: #f3f8d7; color: #000000; background-position: 100% 5px;"><sup><a target="_blank" title="WP-CodeBox howto?" style="color: #cc6600; text-decoration: none; font-family: Arial,Tahoma ! important; font-style: normal ! important; font-variant: normal ! important; font-weight: normal ! important; font-size: 14px ! important; line-height: normal ! important; font-size-adjust: none ! important; font-stretch: normal ! important;">?</a></sup><a href="javascript:;" onclick="javascript:showCodeTxt('p1235code2'); return false;" style="color: #cc6600; text-decoration: none; font-weight: bold;">View Code</a> CPP</div> <div id="hvzpftn" class="wp_codebox" style="border: 1px solid silver; margin: 0px 0px 0.5em; overflow: auto; color: #110000; width: 671px; background-color: #f9f9f9;"> <table style="margin: 0px ! important; border-collapse: collapse; width: 671px;"> <tbody> <tr id="p12352"> <td class="code" id="p1235code2" style="padding: 2px 4px; vertical-align: top;"> <pre class="cpp" style="border-style: none; margin: 0px; padding: 0px; overflow: visible; background-image: none; width: auto; float: none; clear: none; font-size: 12px; line-height: 1.333; text-align: left; font-family: monospace;">tarjan(u)<br>{<br> DFN[u]=Low[u]=++Index // 涓鴻妭鐐箄璁懼畾嬈″簭緙栧彿鍜孡ow鍒濆?br> Stack.push(u) // 灝嗚妭鐐箄鍘嬪叆鏍堜腑<br> for each (u, v) in E // 鏋氫婦姣忎竴鏉¤竟<br> if (v is not visted) // 濡傛灉鑺傜偣v鏈璁塊棶榪?br> tarjan(v) // 緇х畫鍚戜笅鎵?br> Low[u] = min(Low[u], Low[v])<br> else if (v in S) // 濡傛灉鑺傜偣v榪樺湪鏍堝唴<br> Low[u] = min(Low[u], DFN[v])<br> if (DFN[u] == Low[u]) // 濡傛灉鑺傜偣u鏄己榪為氬垎閲忕殑鏍?br> repeat<br> v = S.pop // 灝唙閫鏍堬紝涓鴻寮鴻繛閫氬垎閲忎腑涓涓《鐐?br> print v<br> until (u== v)<br>}</pre> </td> </tr> </tbody> </table> </div> <p style="margin: 0px; padding: 0px 0px 15px;">鎺ヤ笅鏉ユ槸瀵圭畻娉曟祦紼嬬殑婕旂ず銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;">浠庤妭鐐?寮濮婦FS錛屾妸閬嶅巻鍒扮殑鑺傜偣鍔犲叆鏍堜腑銆傛悳绱㈠埌鑺傜偣u=6鏃訛紝DFN[6]=LOW[6]錛屾壘鍒頒簡涓涓己榪為氬垎閲忋傞鏍堝埌u=v涓烘錛寋6}涓轟竴涓己榪為氬垎閲忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;"><img title="image" src="http://www.byvoid.com/blog/wp-content/uploads/2009/04/image2.png" alt="image" style="border-width: 0px; display: inline;" width="523" border="0" height="305"></p> <p style="margin: 0px; padding: 0px 0px 15px;">榪斿洖鑺傜偣5錛屽彂鐜癉FN[5]=LOW[5]錛岄鏍堝悗{5}涓轟竴涓己榪為氬垎閲忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;"><img title="image" src="http://www.byvoid.com/blog/wp-content/uploads/2009/04/image3.png" alt="image" style="border-width: 0px; display: inline;" width="523" border="0" height="335"></p> <p style="margin: 0px; padding: 0px 0px 15px;">榪斿洖鑺傜偣3錛岀戶緇悳绱㈠埌鑺傜偣4錛屾妸4鍔犲叆鍫嗘爤銆傚彂鐜拌妭鐐?鍚戣妭鐐?鏈夊悗鍚戣竟錛岃妭鐐?榪樺湪鏍堜腑錛屾墍浠OW[4]=1銆傝妭鐐?宸茬粡鍑烘爤錛?4,6)鏄í鍙夎竟錛岃繑鍥?錛?3,4)涓烘爲鏋濊竟錛屾墍浠OW[3]=LOW[4]=1銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;"><img title="image" src="http://www.byvoid.com/blog/wp-content/uploads/2009/04/image4.png" alt="image" style="border-width: 0px; display: inline;" width="523" border="0" height="335"></p> <p style="margin: 0px; padding: 0px 0px 15px;">緇х畫鍥炲埌鑺傜偣1錛屾渶鍚庤闂妭鐐?銆傝闂竟(2,4)錛?榪樺湪鏍堜腑錛屾墍浠OW[2]=DFN[4]=5銆傝繑鍥?鍚庯紝鍙戠幇DFN[1]=LOW[1]錛屾妸鏍堜腑鑺傜偣鍏ㄩ儴鍙栧嚭錛岀粍鎴愪竴涓繛閫氬垎閲弡1,3,4,2}銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;"><img title="image" src="http://www.byvoid.com/blog/wp-content/uploads/2009/04/image5.png" alt="image" style="border-width: 0px; display: inline;" width="523" border="0" height="335"></p> <p style="margin: 0px; padding: 0px 0px 15px;">鑷蟲錛岀畻娉曠粨鏉熴傜粡榪囪綆楁硶錛屾眰鍑轟簡鍥句腑鍏ㄩ儴鐨勪笁涓己榪為氬垎閲弡1,3,4,2},{5},{6}銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;">鍙互鍙戠幇錛岃繍琛孴arjan綆楁硶鐨勮繃紼嬩腑錛屾瘡涓《鐐歸兘琚闂簡涓嬈★紝涓斿彧榪涘嚭浜嗕竴嬈″爢鏍堬紝姣忔潯杈逛篃鍙璁塊棶浜嗕竴嬈★紝鎵浠ヨ綆楁硶鐨勬椂闂村鏉傚害涓篛(N+M)銆?/p> <p style="margin: 0px; padding: 0px 0px 15px;">姹傛湁鍚戝浘鐨勫己榪為氬垎閲忚繕鏈変竴涓己鏈夊姏鐨勭畻娉曪紝涓篕osaraju綆楁硶銆侹osaraju鏄熀浜庡鏈夊悜鍥懼強鍏墮嗗浘涓ゆDFS鐨勬柟娉曪紝鍏舵椂闂村鏉傚害涔熸槸O(N+M)銆備笌Trajan綆楁硶鐩告瘮錛孠osaraju綆楁硶鍙兘浼氱◢寰洿鐩磋涓浜涖備絾鏄疶arjan鍙敤瀵瑰師鍥捐繘琛屼竴嬈FS錛屼笉鐢ㄥ緩绔嬮嗗浘錛屾洿綆媧併傚湪瀹為檯鐨勬祴璇曚腑錛孴arjan綆楁硶鐨勮繍琛屾晥鐜囦篃姣擪osaraju綆楁硶楂?0%宸﹀彸銆傛澶栵紝璇arjan綆楁硶涓?a target="_blank" style="color: #cc6600; text-decoration: none;">姹傛棤鍚戝浘鐨勫弻榪為氬垎閲?鍓茬偣銆佹ˉ)鐨凾arjan綆楁硶</a>涔熸湁鐫寰堟繁鐨勮仈緋匯傚涔犺Tarjan綆楁硶錛屼篃鏈夊姪浜庢繁鍏ョ悊瑙f眰鍙岃繛閫氬垎閲忕殑Tarjan綆楁硶錛屼袱鑰呭彲浠ョ被姣斻佺粍鍚堢悊瑙c?/p> <p style="margin: 0px; padding: 0px 0px 15px;">姹傛湁鍚戝浘鐨勫己榪為氬垎閲忕殑Tarjan綆楁硶鏄互鍏跺彂鏄庤?a target="_blank" style="color: #cc6600; text-decoration: none;">Robert Tarjan</a>鍛藉悕鐨勩俁obert Tarjan榪樺彂鏄庝簡姹?a target="_blank" style="color: #cc6600; text-decoration: none;">鍙岃繛閫氬垎閲?/a>鐨凾arjan綆楁硶錛屼互鍙婃眰鏈榪戝叕鍏辯鍏堢殑紱葷嚎Tarjan綆楁硶錛屽湪姝ゅTarjan琛ㄧず宕囬珮鐨勬暚鎰忋?/p> <p style="margin: 0px; padding: 0px 0px 15px;">闄勶細tarjan綆楁硶鐨凜++紼嬪簭</p> <div id="hvzpftn" class="wp_codebox_msgheader" style="border-width: 1px 1px 0px; border-top: 1px solid silver; border-left: 1px solid silver; border-right: 1px solid silver; margin: 0.5em 0px 0px; overflow: hidden; width: 671px; height: 22px; font-weight: bold; background-image: url(http://www.byvoid.com/blog/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: #f3f8d7; color: #000000; background-position: 100% 5px;"><sup><a target="_blank" title="WP-CodeBox howto?" style="color: #cc6600; text-decoration: none; font-family: Arial,Tahoma ! important; font-style: normal ! important; font-variant: normal ! important; font-weight: normal ! important; font-size: 14px ! important; line-height: normal ! important; font-size-adjust: none ! important; font-stretch: normal ! important;">?</a></sup><a href="javascript:;" onclick="javascript:showCodeTxt('p1235code3'); return false;" style="color: #cc6600; text-decoration: none; font-weight: bold;">View Code</a> CPP</div> <div id="hvzpftn" class="wp_codebox" style="border: 1px solid silver; margin: 0px 0px 0.5em; overflow: auto; color: #110000; width: 671px; background-color: #f9f9f9;"> <table style="margin: 0px ! important; border-collapse: collapse; width: 671px;"> <tbody> <tr id="p12353"> <td class="line_numbers" style="padding: 2px 4px; overflow: visible; vertical-align: top; text-align: right; background-color: #ddeeff; color: #666666; table-layout: auto; width: 10px;"> <pre style="border-style: none; margin: 0px; padding: 0px; overflow: visible; background-image: none; width: auto; float: none; clear: none; font-size: 12px; line-height: 1.333; text-align: right;">1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>21<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>31<br>32<br>33<br>34<br>35<br>36<br>37<br>38<br>39<br></pre> </td> <td class="code" id="p1235code3" style="padding: 2px 4px; vertical-align: top;"> <pre class="cpp" style="border-style: none; margin: 0px; padding: 0px; overflow: visible; background-image: none; width: auto; float: none; clear: none; font-size: 12px; line-height: 1.333; text-align: left; font-family: monospace;">void tarjan(int i)<br>{<br> int j;<br> DFN[i]=LOW[i]=++Dindex;<br> instack[i]=true;<br> Stap[++Stop]=i;<br> for (edge *e=V[i];e;e=e->next)<br> {<br> j=e->t;<br> if (!DFN[j])<br> {<br> tarjan(j);<br> if (LOW[j]<LOW[i])<br> LOW[i]=LOW[j];<br> }<br> else if (instack[j] && DFN[j]<LOW[i])<br> LOW[i]=DFN[j];<br> }<br> if (DFN[i]==LOW[i])<br> {<br> Bcnt++;<br> do<br> {<br> j=Stap[Stop--];<br> instack[j]=false;<br> Belong[j]=Bcnt;<br> }<br> while (j!=i);<br> }<br>}<br>void solve()<br>{<br> int i;<br> Stop=Bcnt=Dindex=0;<br> memset(DFN,0,sizeof(DFN));<br> for (i=1;i<=N;i++)<br> if (!DFN[i])<br> tarjan(i);<br>}</pre> </td> </tr> </tbody> </table> </div> <br><img src ="http://www.shnenglu.com/397993401/aggbug/115966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/397993401/" target="_blank">浠樼繑</a> 2010-05-20 20:28 <a href="http://www.shnenglu.com/397993401/archive/2010/05/20/115966.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>hdu 1285 紜畾姣旇禌鍚嶆http://www.shnenglu.com/397993401/archive/2010/05/19/115856.html浠樼繑浠樼繑Wed, 19 May 2010 15:56:00 GMThttp://www.shnenglu.com/397993401/archive/2010/05/19/115856.htmlhttp://www.shnenglu.com/397993401/comments/115856.htmlhttp://www.shnenglu.com/397993401/archive/2010/05/19/115856.html#Feedback0http://www.shnenglu.com/397993401/comments/commentRss/115856.htmlhttp://www.shnenglu.com/397993401/services/trackbacks/115856.html
鍜屽叾浠栫敤鐭╅樀鐨勭◢鏈変笉鍚?br>
//閲囩敤涓寸晫琛ㄧ殑褰㈠紡 浣嗘槸鐢ㄦ暟緇勬潵瀹炵幇 鍏朵腑瑕佺敤C++ 鐨勯槦鍒梥tl 灝介噺浣夸唬鐮佺殑鍙敤搴︽彁楂?br>// 緗戜笂澶у閲囩敤 涓存帴鐭╅樀鐨勬柟寮忔潵鍋氱殑
# include<cstdio>
# include
<iostream>
# include
<queue>
# include
<vector>
using namespace std;
const int maxn = 510;
struct graph
{
    
int edge[maxn][maxn];//edge[i][j] 琛ㄧず絎琲涓妭鐐?nbsp;絎?nbsp;j+1涓竟 鍏跺艱〃紺鴻杈圭殑欏剁偣
    int outdegree[maxn +1];//  欏剁偣鐨勫嚭搴?/span>
    int nvert ;//鑺傜偣鏁?/span>
    int nedge;// 杈規暟  娉ㄦ剰瀹氱偣鎴戜滑鏄粠1 寮濮嬬畻 鐒跺悗杈規暟鎴戜滑鏄粠0 寮濮嬬殑
};
typedef 
struct graph GRAPH;

struct graph g;// 鍥劇殑鍏ㄥ眬鍙橀噺

void init_graph()
{
    
int i;
    g.nedge 
= 0;
    g.nvert 
= 0;
    
for (i = 1; i <=maxn ; i ++ ) g.outdegree[i] = 0;
}
void inert_graph(int x,int y,bool flag )
{
    
//if(g.outdegree[x] > maxn )//瀹歸敊
    g.edge[x][g.outdegree[x]] = y;
    g.outdegree[x] 
++;//鍑哄害 + 1
    if (flag == false)  inert_graph(y,x,true);//濡傛灉鏄棤鍚戝浘 鍙嶅悜涔熻鍔?/span>
    else g.nedge ++;//杈規暟 ++

}
int read_graph(bool flag) //flag 鐢ㄦ潵鎺у埗 鏄惁鏄湁鍚戝浘
{
    
//榪欓噷鍙互鏍規嵁瀹為檯鎯呭喌娣誨姞浠g爜
    int n,i;
    
int x,y;
    init_graph();
    
if (scanf("%d%d",&g.nvert,&n)==EOF)
        
return 0;
    
for (i =1; i <= n; i ++)
    {
        scanf(
"%d%d",&x,&y);
        inert_graph(x,y,
true);//鏄湁鍚戝浘
    }
    
return 1;
}

//鎷撴墤鎺掑簭  涓嬮潰鏄痶op 鎺掑簭鎵闇瑕佺殑涓滀笢
int sorted[maxn];
int indegree[maxn]; //璁$畻鍏ュ害
int visted[maxn];
void topsorted()
{
    queue
<int> zeroin;
    
int x,y;
    
int i,j;
    
//鍒濊瘯鍖?nbsp;鍏ュ害鏁扮粍
    for (i = 1; i <= maxn ; i ++)  indegree[i] = 0;
    
//璁$畻鍏ュ害
    for (i = 1; i <= g.nvert ; i++ )
        
for (j = 0; j < g.outdegree[i]; j++// 鎵浠ヨ繖閲屾垜浠槸浠?nbsp;0 寮濮?/span>
            indegree[g.edge[i][j]] ++;

    
for(i = 1; i <= g.nvert ; i ++)
    {
    
//for (i = g.nvert; i >= 1 ; i --)
        if (indegree[i] == 0) zeroin.push(i);
    }
    j 
= 0;
    memset(visted,
0,sizeof(visted));
    
for(j = 1;j <= g.nvert;j++)//  鍥犱負棰樼洰鐨勫師鍥?鏀懼純闃熷垪
    {
        
for(i = 1;i<=g.nvert;i++ )
        {
            
if(visted[i] == 0 && indegree[i] == 0)
            {
                sorted[j] 
= i,visted[i] = 1;
                
for(int k = 0;k< g.outdegree[i];k++)
                    indegree[g.edge[i][k]]
--;
                
break;
            }
        }
    }

    
//if(j != g.nvert) ;//琛ㄦ槑鍙湁 j涓畾鐐規壘鍒?/span>
}

void print_graph()
{
    
int i,j;
    
for (i = 1; i <= g.nvert; i ++)
    {
        printf(
"%d: ",i);
        
for (j = 0; j < g.nvert ; j ++)
            printf(
" %d",g.edge[i][j]);
        printf(
"\n");
    }
}
int main()
{
    freopen(
"in.txt","r",stdin);

    
while (read_graph(true)==1)
    {

        topsorted();
        
//print_graph();
        for (int i = 1; i <= g.nvert; i ++)
            printf(i
==1?"%d":" %d",sorted[i]);
        printf(
"\n");
    }
    
return 0;
}





浠樼繑 2010-05-19 23:56 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲日本国产| 国产精品一区久久久| 亚洲人久久久| 亚洲国产二区| 欧美激情女人20p| 免费在线观看一区二区| 亚洲国产精品久久精品怡红院| 另类综合日韩欧美亚洲| 久久久久九九九九| 亚洲国产日韩综合一区| 亚洲激精日韩激精欧美精品| 欧美成人资源网| 99国内精品久久| 一区二区三区四区国产| 国产精品一区毛片| 久久久爽爽爽美女图片| 久久久最新网址| 亚洲黄网站黄| 国产精品综合视频| 午夜精彩国产免费不卡不顿大片| 亚洲素人在线| 国产精品永久在线| 久久久伊人欧美| 久久一区二区三区av| 亚洲精品一区二区三区四区高清| 久久xxxx精品视频| 久久精品国产综合| 亚洲黄色av一区| 日韩网站在线| 国产欧美日韩高清| 老司机精品视频一区二区三区| 久久中文精品| 国产精品99久久久久久宅男| 亚洲一区三区在线观看| 欧美视频福利| 久久精品日产第一区二区三区| 久久人91精品久久久久久不卡 | 欧美日韩另类在线| 性色一区二区| 六月丁香综合| 亚洲视频在线一区观看| 欧美亚洲免费高清在线观看| 在线观看日韩专区| 日韩一区二区久久| 国产一区二区三区四区在线观看 | 99这里只有精品| 国产精品视频在线观看| 狂野欧美一区| 欧美日韩免费一区| 久久久免费精品视频| 欧美激情一区二区三区| 午夜亚洲性色视频| 噜噜噜在线观看免费视频日韩| 在线视频欧美日韩| 亚洲精品免费一二三区| 国产精品一区二区三区免费观看 | 久久五月天婷婷| 欧美精品自拍偷拍动漫精品| 欧美一站二站| 欧美激情一区| 久久成人人人人精品欧| 欧美剧在线观看| 久久亚洲私人国产精品va媚药| 欧美日韩国产精品 | 久久视频这里只有精品| 亚洲天堂网在线观看| 久久久久9999亚洲精品| 亚洲一区www| 麻豆国产精品va在线观看不卡| 性色av香蕉一区二区| 欧美成人免费小视频| 久久久精品国产免费观看同学| 欧美伊久线香蕉线新在线| 99精品国产福利在线观看免费| 欧美一区二区视频观看视频| 正在播放亚洲一区| 老牛国产精品一区的观看方式| 香蕉久久夜色精品国产| 欧美金8天国| 欧美va亚洲va香蕉在线| 国产农村妇女毛片精品久久莱园子| 亚洲大胆美女视频| 欧美日本三区| 欧美成人久久| 国产视频久久| 日韩一级免费观看| 91久久久在线| 久久精品女人| 欧美在线影院| 国产精品美女视频网站| 亚洲精品美女在线观看| 亚洲丁香婷深爱综合| 欧美亚洲免费电影| 午夜免费久久久久| 欧美日韩中文在线| 91久久久亚洲精品| 亚洲第一在线综合网站| 欧美一区二区三区免费在线看 | 午夜精品在线观看| 亚洲香蕉视频| 欧美日韩精品二区第二页| 亚洲第一福利社区| 亚洲第一中文字幕在线观看| 久久成人免费日本黄色| 欧美伊人久久| 国产精品亚洲综合色区韩国| 一区二区三区福利| 亚洲免费黄色| 欧美精品一区二区视频 | 一区二区三区在线视频观看| 亚洲欧洲av一区二区| 午夜久久资源| 国产精品免费一区豆花| 亚洲视频一区| 亚洲一区二区三区视频播放| 欧美日韩黄视频| 亚洲剧情一区二区| 中国成人亚色综合网站| 欧美日韩国产在线播放| 亚洲韩日在线| 99国产精品视频免费观看| 欧美精品v日韩精品v国产精品 | 欧美a级理论片| 在线欧美不卡| 免费日本视频一区| 亚洲高清av在线| 日韩视频在线观看一区二区| 欧美激情第二页| 亚洲日韩第九十九页| 在线视频你懂得一区二区三区| 欧美日韩综合| 亚洲一区二区三区中文字幕| 欧美在线一级视频| 国语自产精品视频在线看抢先版结局| 欧美一区二区视频在线| 久久夜色精品国产| 在线免费观看视频一区| 欧美电影美腿模特1979在线看 | 亚洲成色777777女色窝| 毛片基地黄久久久久久天堂| 亚洲国语精品自产拍在线观看| 一本色道久久综合狠狠躁篇怎么玩| 欧美日韩精品三区| 亚洲一区影院| 久久不见久久见免费视频1| 国产丝袜美腿一区二区三区| 久久精品国产精品 | 亚洲欧美日韩在线一区| 久久青青草原一区二区| 亚洲国产一区二区在线| 亚洲蜜桃精久久久久久久| 你懂的视频一区二区| 1769国产精品| 欧美不卡视频一区发布| 亚洲看片一区| 欧美一级午夜免费电影| 国产在线国偷精品产拍免费yy| 久久久久久色| 亚洲精品在线观| 欧美一区二区三区四区视频| 尤物精品在线| 欧美日韩一区成人| 午夜精品久久久久久久99水蜜桃| 老鸭窝毛片一区二区三区| 日韩视频三区| 国产精品自拍小视频| 久热精品在线| 这里是久久伊人| 久久蜜臀精品av| 一区二区黄色| 国产日韩欧美二区| 欧美成人视屏| 亚洲综合国产精品| 欧美激情小视频| 亚洲欧美中文日韩v在线观看| 伊人精品视频| 欧美色另类天堂2015| 久久精品综合网| 99riav久久精品riav| 久久在线播放| 亚洲一区二区av电影| 伊人久久综合97精品| 欧美亚一区二区| 久久亚洲精品一区二区| 在线亚洲欧美视频| 欧美成人亚洲| 欧美制服第一页| 亚洲精品视频一区| 国产欧美精品日韩| 欧美激情女人20p| 欧美在线日韩| 99精品视频免费在线观看| 免费观看亚洲视频大全| 国产老女人精品毛片久久| 久久久久88色偷偷免费| 亚洲乱码国产乱码精品精天堂| 久久精品国产一区二区电影| 亚洲伦理在线观看| 狠狠色狠狠色综合日日91app| 欧美日韩免费在线|