锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美日韩在线播放一区,午夜天堂精品久久久久,欧美在线亚洲一区http://m.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://m.shnenglu.com/397993401/archive/2010/09/02/125706.html浠樼繑浠樼繑Thu, 02 Sep 2010 15:48:00 GMThttp://m.shnenglu.com/397993401/archive/2010/09/02/125706.htmlhttp://m.shnenglu.com/397993401/comments/125706.htmlhttp://m.shnenglu.com/397993401/archive/2010/09/02/125706.html#Feedback0http://m.shnenglu.com/397993401/comments/commentRss/125706.htmlhttp://m.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://m.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://m.shnenglu.com/397993401/archive/2010/05/20/115966.html</guid><wfw:comment>http://m.shnenglu.com/397993401/comments/115966.html</wfw:comment><comments>http://m.shnenglu.com/397993401/archive/2010/05/20/115966.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/397993401/comments/commentRss/115966.html</wfw:commentRss><trackback:ping>http://m.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://m.shnenglu.com/397993401/aggbug/115966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/397993401/" target="_blank">浠樼繑</a> 2010-05-20 20:28 <a href="http://m.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://m.shnenglu.com/397993401/archive/2010/05/19/115856.html浠樼繑浠樼繑Wed, 19 May 2010 15:56:00 GMThttp://m.shnenglu.com/397993401/archive/2010/05/19/115856.htmlhttp://m.shnenglu.com/397993401/comments/115856.htmlhttp://m.shnenglu.com/397993401/archive/2010/05/19/115856.html#Feedback0http://m.shnenglu.com/397993401/comments/commentRss/115856.htmlhttp://m.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>
            国产在线观看精品一区二区三区| 免费不卡欧美自拍视频| 欧美精品在线免费播放| 久久夜色精品国产| 久久伊人免费视频| 免费观看久久久4p| 欧美在线视频导航| 欧美一区激情视频在线观看| 亚洲男人影院| 亚洲精品永久免费| 美女视频黄 久久| 亚洲影院色无极综合| 亚洲精品乱码久久久久| 亚洲精品黄网在线观看| 99视频一区二区三区| aa级大片欧美三级| 亚洲天堂av在线免费观看| 亚洲久久一区| 亚洲欧美国产另类| 久久精品国产综合精品| 欧美a级片一区| 日韩一区二区精品葵司在线| 亚洲午夜国产成人av电影男同| 香蕉免费一区二区三区在线观看| 久久人人爽爽爽人久久久| 美女91精品| 国产精品久久久久91| 国产在线不卡精品| av成人激情| 久久久久国产精品一区| 亚洲国产三级网| 亚洲美女视频| 久久精品国产在热久久| 欧美成人自拍| 国产在线乱码一区二区三区| 日韩亚洲欧美高清| 麻豆成人91精品二区三区| av成人福利| 美日韩精品免费观看视频| 国产精品九九久久久久久久| 91久久精品国产91久久性色tv| 亚洲欧美中日韩| 最新亚洲视频| 久久综合伊人77777| 国产精品成人免费视频 | 亚洲少妇最新在线视频| 久久色在线播放| 国产精品稀缺呦系列在线| 亚洲精品国产欧美| 久久夜色精品国产| 亚洲综合日本| 欧美日韩午夜在线| 亚洲另类自拍| 欧美激情片在线观看| 久久精品毛片| 国产日本欧美一区二区三区在线| 一本久久青青| 国产精品极品美女粉嫩高清在线| 久久婷婷国产综合精品青草| 亚洲福利在线观看| 亚洲一区二区三区高清不卡| 欧美不卡在线视频| 欧美暴力喷水在线| 欧美在线关看| 国产视频在线观看一区二区三区| 亚洲欧美激情诱惑| 亚洲免费在线观看视频| 国产精品女人毛片| 亚洲一区二区视频在线| 亚洲精品一区二区三区不| 欧美成人一区二区| 一区二区高清在线| av不卡在线| 国产欧美91| 狂野欧美性猛交xxxx巴西| 久久国产视频网| 亚洲第一区中文99精品| 亚洲大黄网站| 欧美日韩成人| 午夜亚洲视频| 久久精品国产99精品国产亚洲性色| 好吊色欧美一区二区三区四区 | 亚洲一区二区三区国产| av成人手机在线| 国产日韩精品在线观看| 久久久999精品| 欧美gay视频激情| 亚洲视频精选在线| 欧美一区二区在线观看| 亚洲电影一级黄| 99天天综合性| 国产综合久久| 亚洲黄色一区| 国产精品一区一区| 亚洲电影下载| 国产美女精品一区二区三区| 老司机一区二区| 欧美日韩高清在线播放| 欧美专区第一页| 欧美国产日韩在线| 久久精品国产77777蜜臀| 欧美gay视频激情| 久久成人免费电影| 欧美日韩不卡在线| 你懂的一区二区| 国产精品无码专区在线观看| 美女视频网站黄色亚洲| 国产精品99一区| 欧美成人xxx| 国产精品自拍三区| 亚洲国产va精品久久久不卡综合| 国产精品久久久久久久一区探花 | 国产亚洲精品7777| 亚洲精品国产精品久久清纯直播| 国产精品日韩在线一区| 欧美福利一区二区| 国产丝袜一区二区| 一本一道久久综合狠狠老精东影业| 国产原创一区二区| 亚洲图片你懂的| 一区二区国产在线观看| 麻豆av一区二区三区久久| 久久精品盗摄| 国产精品区一区二区三区| 亚洲精品一线二线三线无人区| 一区在线播放| 欧美伊人久久久久久久久影院 | 91久久在线视频| 在线电影一区| 久久国产欧美| 久久婷婷亚洲| 狠狠色丁香久久综合频道 | 久久天天狠狠| 久久精品视频免费观看| 国产精品网站在线播放| 亚洲一品av免费观看| 99在线精品观看| 欧美日韩播放| 一级成人国产| 性欧美暴力猛交69hd| 欧美视频一区在线观看| av成人免费| 欧美一区二区视频网站| 国产欧美日韩麻豆91| 欧美亚洲视频一区二区| 久久成人精品电影| 国外成人在线视频| 久久综合精品国产一区二区三区| 欧美成人精品一区二区| 亚洲国产精品久久久久| 欧美成人综合| 一本色道久久综合狠狠躁篇的优点 | 亚洲女女女同性video| 欧美日韩视频一区二区三区| 亚洲精品在线一区二区| 亚洲欧美日本日韩| 国产亚洲女人久久久久毛片| 欧美影片第一页| 免费在线成人av| 亚洲精品少妇30p| 欧美三级电影大全| 亚洲伊人网站| 米奇777超碰欧美日韩亚洲| 亚洲电影网站| 欧美日韩综合视频网址| 亚洲免费中文| 欧美电影免费观看高清| 一区二区三区四区五区视频 | 亚洲一区三区电影在线观看| 国产精品毛片高清在线完整版| 久久免费视频在线观看| 揄拍成人国产精品视频| 欧美激情1区| 亚洲女女女同性video| 男人的天堂成人在线| 一区二区三区日韩欧美| 国产日韩欧美不卡| 欧美精品一区在线播放| 亚洲一区亚洲二区| 欧美电影免费观看网站| 亚洲一品av免费观看| 精品999日本| 欧美日韩中文另类| 久久成人综合视频| 日韩一级免费观看| 久久亚洲精品伦理| 亚洲永久免费| 亚洲欧洲三级| 国产综合色产在线精品| 欧美日韩在线综合| 欧美激情视频一区二区三区不卡| 亚洲欧美日韩精品久久久久| 欧美国产日本| 久久狠狠婷婷| 亚洲一区二区视频在线| 亚洲人成人99网站| 黄色欧美日韩| 国产视频观看一区| 欧美三区在线观看| 欧美日韩久久不卡|