锘??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>
            国产精品亚洲综合久久| 米奇777超碰欧美日韩亚洲| 欧美国产大片| 亚洲作爱视频| 中文久久精品| 国产日韩欧美在线观看| 麻豆精品视频| 欧美成在线观看| 亚洲性av在线| 久久精品亚洲一区| 亚洲精品久久久久久下一站| 亚洲理论在线| 国产乱码精品一区二区三区五月婷| 久久www成人_看片免费不卡| 久久久精品国产一区二区三区| 136国产福利精品导航网址| 亚洲国产成人av好男人在线观看| 欧美精品免费观看二区| 亚洲视频免费在线观看| 亚洲欧美在线一区二区| 亚洲大胆人体在线| 99综合精品| 好吊一区二区三区| 99综合在线| 在线观看久久av| 一区二区三区不卡视频在线观看| 国产九区一区在线| 亚洲精品一区二区三区99| 国产精品亚洲精品| 亚洲国产一区二区三区青草影视 | 久久丁香综合五月国产三级网站| 亚洲国产高清在线| 亚洲一区二区免费| 亚洲精品美女免费| 午夜在线不卡| 亚洲一区bb| 久久综合伊人77777尤物| 午夜伦理片一区| 欧美顶级少妇做爰| 卡通动漫国产精品| 国产乱码精品一区二区三区忘忧草| 亚洲国产91色在线| 伊人婷婷欧美激情| 亚洲你懂的在线视频| 日韩视频免费观看高清完整版| 欧美一区二区三区精品| 亚洲婷婷综合久久一本伊一区| 久久综合色天天久久综合图片| 亚洲欧美激情四射在线日 | 激情综合久久| 性色av香蕉一区二区| 亚洲欧美春色| 欧美三级黄美女| 亚洲日本免费| 亚洲精品视频中文字幕| 麻豆精品在线视频| 老鸭窝亚洲一区二区三区| 国产亚洲精品一区二555| 亚洲欧美国产高清va在线播| 亚洲欧美激情精品一区二区| 欧美日韩a区| 日韩亚洲视频在线| 一本色道久久综合亚洲精品不| 免费成人毛片| 欧美激情1区2区| 亚洲国产一区二区三区在线播| 久久久福利视频| 麻豆av福利av久久av| 国精品一区二区三区| 久久精品日产第一区二区| 免费观看一区| 亚洲精品在线观看免费| 欧美欧美天天天天操| 91久久久亚洲精品| 日韩网站在线观看| 欧美日本乱大交xxxxx| 亚洲精品中文在线| 亚洲尤物在线| 国产一区在线观看视频| 久久精品人人做人人爽| 欧美激情五月| 亚洲视频999| 国产伦精品一区二区| 久久成人综合网| 91久久综合| 欧美亚洲色图校园春色| 狠狠色狠色综合曰曰| 老妇喷水一区二区三区| 亚洲精品国产拍免费91在线| 亚洲欧美日韩直播| 韩国一区电影| 欧美精品精品一区| 亚洲综合成人在线| 欧美va亚洲va国产综合| 一区二区三区鲁丝不卡| 国产精品丝袜91| 鲁鲁狠狠狠7777一区二区| 99成人在线| 男女av一区三区二区色多| 中文网丁香综合网| 国产一区91精品张津瑜| 欧美电影在线观看| 欧美一区二区性| 亚洲精品字幕| 狂野欧美激情性xxxx| 国产精品99久久久久久www| 国产午夜亚洲精品不卡| 欧美美女操人视频| 欧美伊人影院| 亚洲精品国久久99热| 久久精品视频免费| 亚洲精品欧美极品| 国产毛片久久| 欧美日韩国产一区精品一区 | 毛片av中文字幕一区二区| 在线综合亚洲欧美在线视频| 免费视频一区| 欧美中文字幕| 一区二区久久| 亚洲人屁股眼子交8| 国产一区二区三区高清| 欧美午夜免费| 欧美日韩成人在线播放| 蜜桃av一区二区| 欧美在线看片| 亚洲欧美久久久| 亚洲图片欧美一区| 亚洲精品国产精品国自产观看| 老巨人导航500精品| 久久精品国产清高在天天线| 亚洲一区黄色| 亚洲一级一区| 亚洲最新视频在线| aa亚洲婷婷| 一个人看的www久久| 亚洲欧洲中文日韩久久av乱码| 一区二区亚洲精品| 国内自拍一区| 尹人成人综合网| 激情久久一区| 亚洲国产一区二区三区青草影视 | 亚洲毛片一区| 亚洲欧洲在线一区| 亚洲精选一区二区| 99riav国产精品| 亚洲天堂av电影| 亚洲一区三区在线观看| 亚洲免费中文字幕| 亚洲欧美综合网| 久久精精品视频| 久热精品在线| 亚洲韩国青草视频| 日韩天堂在线观看| 亚洲尤物在线视频观看| 午夜在线精品偷拍| 久久婷婷国产综合国色天香| 久久视频一区二区| 欧美精品亚洲精品| 国产精品你懂的在线| 国产一区二区三区高清| 狠狠综合久久av一区二区老牛| 亚洲成色777777在线观看影院| 亚洲欧洲久久| 中文在线一区| 久久精品一区中文字幕| 欧美成人精品在线视频| 最新国产成人在线观看| 宅男精品视频| 久久噜噜亚洲综合| 欧美国产日本高清在线| 国产精品久久久久久久久| 国产亚洲视频在线观看| 亚洲激情成人网| 午夜精品美女久久久久av福利| 蜜臀a∨国产成人精品| 亚洲六月丁香色婷婷综合久久| 亚洲自拍电影| 欧美成人亚洲成人日韩成人| 国产精品久久看| 亚洲国产日韩综合一区| 亚洲一区日韩在线| 欧美成人精品不卡视频在线观看 | 亚洲福利国产| 午夜精品美女自拍福到在线| 六月丁香综合| 国产欧美日韩另类视频免费观看| 亚洲国产高潮在线观看| 亚洲综合导航| 亚洲欧洲一区二区三区| 欧美一级视频一区二区| 欧美日本在线视频| 黄色日韩网站| 香蕉国产精品偷在线观看不卡| 免费观看欧美在线视频的网站| 亚洲性图久久| 欧美婷婷在线| 亚洲日本精品国产第一区| 久久精品国产精品亚洲| 亚洲视频福利| 欧美日韩 国产精品|