锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久亚洲国产精品123区,2021国产精品久久精品,久久精品国产第一区二区http://www.shnenglu.com/tianlearn-language/archive/2010/12/11/136164.html鐢板叺鐢板叺Sat, 11 Dec 2010 08:48:00 GMThttp://www.shnenglu.com/tianlearn-language/archive/2010/12/11/136164.htmlhttp://www.shnenglu.com/tianlearn-language/comments/136164.htmlhttp://www.shnenglu.com/tianlearn-language/archive/2010/12/11/136164.html#Feedback0http://www.shnenglu.com/tianlearn-language/comments/commentRss/136164.htmlhttp://www.shnenglu.com/tianlearn-language/services/trackbacks/136164.html絎竴嬈″啓嬈″皬鐢熸垚鏍戯紝娌℃兂鍒?/div>
鎬濇兂灝辨槸錛氭眰涓嬈℃渶灝忕敓鎴愭爲錛岃褰曟墍鐢ㄥ埌鐨勮竟錛岀劧鍚庝笉鐢ㄦ墍鏈夌涓嬈$敤鍒扮殑杈瑰皾璇曟瀯鎴愭瀯鎴愭渶灝忕敓鎴愭爲銆?/div>
鐢↘ruskal鍏堟眰鏈灝忕敓鎴愭爲錛岀粨鏋滃嵆涓簃in錛屾妸鎵鐢ㄥ埌鐨勮竟璁板綍涓嬫潵錛堣繖閲屾槸璁板綍鐨勫搴旂殑涓嬭〃錛夛紝鐒跺悗鏋氫婦榪欎簺杈癸紝
姣忔鍘繪帀涓涓竟姹備竴嬈℃渶灝忕敓鎴愭爲錛岀粨鏋滀負tmin錛屽鏋滆兘澶熸垚鏈灝忕敓鎴愭爲騫朵笖tmin==min錛屽垯璇存槑鏈灝忕敓鎴愭爲涓嶅敮涓
#include<iostream> //poj 1679
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX = 101;
int n, m;

struct edge
{
    int x;
    int y;
    int len;
}E[MAX*MAX];

int fa[MAX];
int indexEdge[MAX];
int index;
bool cmp(const edge &a, const edge &b)
{
    return a.len < b.len;
}

int find(int x)
{
    if(fa[x] == x)return x;
    return fa[x] = find(fa[x]);
}

int Kruskal(int location)  //涓嶇敤location浣嶇疆鐨勮竟
{
    int ans = 0;
    int tx, ty;
    int cnt = 0;
    if (location == -1)index = 0;//location == -1 絎竴嬈℃眰鏈灝忕敓鎴愭爲錛宨ndexEdge[index]綰綍絎琲ndex鐢ㄥ埌鐨勮竟鐨勪笅鏍?/div>
    for(int k = 1; k <= n; k ++)fa[k] = k;

    for(int i = 0; i < m; i ++)
    {
        if(i == location)continue;
        tx = find(E[i].x);
        ty = find(E[i].y);
        if(tx != ty)
        {
            fa[tx] = ty;
            ans += E[i].len;
            cnt ++;
            if(location == -1)//絎竴嬈℃渶灝忕敓鎴愭爲鐨勬椂鍊欐妸location緗負-1
            {
                indexEdge[index] = i;
                index ++;
            }
            if(cnt == n - 1)break;
        }
    }

    if(cnt == n - 1)return ans;
    return -1;
}

int main()
{
    int t, i;
    scanf("%d",&t);
    while(t --)
    {
        memset(E, 0, sizeof E);
        memset(indexEdge, 0, sizeof indexEdge);

        scanf("%d %d",&n, &m);

        for(i = 0; i < m; i ++)
            scanf("%d %d %d",&E[i].x, & E[i].y , & E[i].len);

        sort(E, E + m, cmp);
        
        int min = Kruskal(-1);    
        int tmin = (1<<20), temp;
        //cout << index << endl;
        
        for(i = 0; i < index; i ++)
        {
            //cout <<i <<' '<< indexEdge[i]<< endl;
            temp = Kruskal(indexEdge[i]);
            if(temp != -1 && temp < tmin)
                tmin = temp;
        }
        
        if(tmin == min)
            printf("Not Unique!\n");
        else printf("%d\n",min);
    }
                           
    return 0;
}


鐢板叺 2010-12-11 16:48 鍙戣〃璇勮
]]>AOJ 236 Cow Picnic , poj 3256http://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125276.html鐢板叺鐢板叺Mon, 30 Aug 2010 07:49:00 GMThttp://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125276.htmlhttp://www.shnenglu.com/tianlearn-language/comments/125276.htmlhttp://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125276.html#Feedback0http://www.shnenglu.com/tianlearn-language/comments/commentRss/125276.htmlhttp://www.shnenglu.com/tianlearn-language/services/trackbacks/125276.html
Cow Picnic
Time Limit: 2000 ms   Memory Limit: 64 MB
Total Submission: 1   Accepted: 1
Description
The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to itself).

The cows want to gather in the same pasture for their picnic, but (because of the one-way paths) some cows may only be able to get to some pastures. Help the cows out by figuring out how many pastures are reachable by all cows, and hence are possible picnic locations.

Input
Line 1: Three space-separated integers, respectively: K, N, and M
Lines 2..K+1: Line i+1 contains a single integer (1..N) which is the number of the pasture in which cow i is grazing.
Lines K+2..M+K+1: Each line contains two space-separated integers, respectively A and B (both 1..N and A != B), representing a one-way path from pasture A to pasture B.

Output
Line 1: The single integer that is the number of pastures that are reachable by all cows via the one-way paths.

Sample Input
2 4 4
2
3
1 2
1 4
2 3
3 4
 

Sample Output
2[EOL][EOF]

Hint
The cows can meet in pastures 3 or 4.

Source
USACO 2006 December Silver 

浠庢瘡涓墰寮濮嬫眰涓嬈″崟婧愭渶鐭礬寰勶紝鍋囪璧風偣鏄疿錛屽鏋滀粠X鑳藉埌i (di[i]!=INF) 錛宑nt[i]++錛岀敤鏉ョ粺璁¤兘鍒拌揪 i 鐐圭殑鐗涚殑鏁伴噺銆?br>
緇撴灉灝辨槸婊¤凍cnt[i]==K鐨勬暟閲忥紝鍗砳鐐規墍鏈夌殑鐗涢兘鍙互鍒拌揪銆?br>
鐢╯pfa姹傦紝spfa鍦ㄨ繖閲屼笉鏄眰鏈孌佃礬寰勶紝鍙鍒頒簡灝辮錛屼笉闇瑕佹槸鏈鐭殑錛屽洜姝や細鏇村揩涓鐐廣?br>
#include<iostream>
#include
<time.h>
#include
<vector>
#include
<queue>
using namespace std;
const int MAX=1001,INF=0x0fffffff;
vector
<int> mp[MAX];
int d[MAX], cnt[MAX];
int K,N,M;
int stay[101];
void spfa(int x)
{
     
for(int i=1; i<=N; i++)
             d[i]
=INF;
     queue
<int>q;
     q.push(x);
     d[x]
=0;
     
while(q.size())
     {  
         
          
int u=q.front(); q.pop(); 
          
for(int i=0; i<mp[u].size(); i++)
          {
                  
if(d[mp[u][i]]==INF)
                  {
                       d[mp[u][i]]
=d[u]+1;
                       q.push(mp[u][i]);
                  }
          }
                    
     }
}

int main()
{
    cin
>>K>>N>>M;
    
    
for(int i=1; i<=K; i++)
            cin
>>stay[i];
    
    
for(int i=1,s,t; i<=M; i++)
            {
                     cin
>>s>>t;
                     mp[s].push_back(t);
            }
    
    
for(int i=1; i<=K; i++)
    {
       spfa(stay[i]);    
       
for(int i=1; i<=N; i++)
               
if(d[i]!=INF)cnt[i]++;   
    }
    
    
int ans=0;
    
    
for(int i=1; i<=N; i++)  
            
if(cnt[i]==K)ans++;
    
    cout
<<ans<<endl;        
    system(
"pause");
    
return 0;
}



鐢板叺 2010-08-30 15:49 鍙戣〃璇勮
]]>poj 1274 The Perfect Stall http://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125252.html鐢板叺鐢板叺Mon, 30 Aug 2010 02:09:00 GMThttp://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125252.htmlhttp://www.shnenglu.com/tianlearn-language/comments/125252.htmlhttp://www.shnenglu.com/tianlearn-language/archive/2010/08/30/125252.html#Feedback0http://www.shnenglu.com/tianlearn-language/comments/commentRss/125252.htmlhttp://www.shnenglu.com/tianlearn-language/services/trackbacks/125252.html
浜屽垎鍥劇殑鏈澶у尮閰嶏紝鍔犱竴涓簮鐐癸紝榪欎釜婧愮偣鍒板乏杈規墍鏈夐《鐐瑰姞涓鏉¤竟錛屾潈鍊間負1. 銆傚悓鐞嗭紝鍔犱竴涓粓鐐癸紝鎵鏈夊彸杈圭殑瀹氱偣鍒拌繖涓粓鐐規湁鏉¤竟錛屾潈鍊間負1. 榪欐牱浜屽垎鍥劇殑鏈澶у尮閰嶅氨杞崲鎴愪簡鏈澶ф祦闂銆?/span>

#include<iostream>
#include
<queue>
#include
<cstring>
using namespace std;
const int MAX=405;
int cap[MAX][MAX]={0};
int flow[MAX][MAX]={0};
int pre[MAX],m[MAX];
int N, M,S,T;
const int INF=10000000;

int bfs(int s)
{
    memset(m,
0,sizeof m);  
    memset(pre,
0,sizeof pre);
    queue
<int> q;
    q.push(s);
    m[s]
=INF;
    
while(!q.empty())
    {
            
int u=q.front(); q.pop();
            
for(int v=0; v<=N+M+1; v++)
                    
if(!m[v]&&cap[u][v]>flow[u][v])
                    {
                         pre[v]
=u;
                         m[v]
= m[u]>cap[u][v]-flow[u][v]?cap[u][v]-flow[u][v]:m[u];
                         q.push(v);
                    }
    }
    
   
if(m[T]==0)return 0;
   
   
for(int u=T; u!=S ; u=pre[u])
   {
           flow[pre[u]][u]
+=m[T];
           flow[u][pre[u]]
-=m[T];
   }
   
return m[T];
}

int main()
{
    
    
while(cin>>N>>M)
    {    memset(cap,
0,sizeof cap);
         memset(flow,
0,sizeof flow);
         
for(int i=1; i<=N; i++)
         {
            
int c,e;
            cin
>>c;
            
for(int j=1; j<=c; j++)
                   {
                         cin
>>e;
                         e
=e+N;
                         cap[i][e]
=1;
                   } 
         } 
         S
=0
         T
=N+M+1;
         
for(int i=1; i<=N; i++)
            cap[
0][i]=1;
            
         
for(int i=1; i<=M; i++)
            cap[N
+i][T]=1;
    
         
int ans=0;
         
while(1)
         {
            
int temp=bfs(S);
            
if(temp==0)break;
            
else ans+=temp;
         }
    
         cout
<<ans<<endl;
    }   
    system(
"pause");
    
return 0;
}


鐢板叺 2010-08-30 10:09 鍙戣〃璇勮
]]>
poj 1273 Drainage Ditcheshttp://www.shnenglu.com/tianlearn-language/archive/2010/08/25/124683.html鐢板叺鐢板叺Wed, 25 Aug 2010 07:30:00 GMThttp://www.shnenglu.com/tianlearn-language/archive/2010/08/25/124683.htmlhttp://www.shnenglu.com/tianlearn-language/comments/124683.htmlhttp://www.shnenglu.com/tianlearn-language/archive/2010/08/25/124683.html#Feedback0http://www.shnenglu.com/tianlearn-language/comments/commentRss/124683.htmlhttp://www.shnenglu.com/tianlearn-language/services/trackbacks/124683.html 
         璧よ8瑁哥殑鏈澶ф祦闂錛屼篃鏄垜鍐欑涓涓渶澶ф祦錛屾槸鍏ラ棬鐨勫ソ棰樸?br>
         鍙戠幇鐪嬩唬鐮佹湁鏃跺欐瘮鐪嬩功鏇村鏄撴噦錛岀湅鏈澶ф祦宸茬粡鐪嬩簡濂藉嚑澶╀功浜嗭紝閮芥槸鏅曚箮涔庣殑錛屽弬鑰冧簡涓涓嬪埆浜虹殑浠g爜錛屼技涔庢湁浜涗簡瑙d簡銆?br>
      Ford-Fulkerson鏂規硶鐨勫騫胯礬綆楁硶
      姣忔鐢╠fs瀵繪壘鍙騫胯礬寰勶紝璇ヨ礬寰勪笂鐨勬墍鏈夎竟鐨勫閲忓潎瑕佹槸姝f暟錛屽鏋滄壘鍒板氨鍙栬璺緞涓婃墍鏈夊閲忕殑鏈灝忓間綔涓哄鍔犵殑嫻併傚鏋滀笉瀛樺湪鍒欒鏄庡凡緇忔槸鏈澶ф祦錛岀粨鏉熴?br>
涓嬮潰榪欎袱涓▼搴忓湪hdu鏈夌偣灝忛棶棰橈紝絎笁涓槸鍦ㄤ袱涓狾J涓婇兘鍙互鐨勩?br>

#include<iostream>
using namespace std;
int map[250][250];
int pre[250];
bool visit[250];
int m,n,minflow;
const int INF=0x7fffffff/1000;

int dfs(int v)
{
    visit[v]
=true;
    
if(v==n)return 1;
    
for(int i=1; i<=n; i++)
            
if(map[v][i]>0&&!visit[i])
              { 
                  pre[i]
=v;
                  minflow
=minflow>map[v][i]?map[v][i]:minflow;
                  
if(dfs(i))return true;
              }
    
return 0;
}

int maxflow()
{
    
int maxf=0;
    
while(1)
    {
           memset(pre,
0,sizeof pre);
           minflow
=INF;
           memset(visit,
0,sizeof visit);
           pre[
1]=-1;
           
if(dfs(1))
           {
                    
                     
int inc=minflow;
                     
int t=n;
                     
while(pre[t]!=-1)
                     {
                          
int qq=pre[t];
                          map[qq][t]
-=inc;
                          map[t][qq]
+=inc;
                          t
=qq;
                     }
                     maxf
+=inc;
           }
           
else break;
    }
    
return maxf;
}

int main()
{
    
while(cin>>m>>n)
    {
       
int s,t,c;
       memset(map,
0,sizeof map);
       
while(m--)
       {
                cin
>>s>>t>>c;
                map[s][t]
+=c; 
       }               
       cout
<<maxflow()<<endl;
    }
    
   system(
"pause");
   
return 0;   
}

鐢˙FS鐨凟dmonds-Karp綆楁硶
#include<iostream>
#include
<queue>
using namespace std;
int map[250][250];
int pre[250];
bool visit[250];
int m,n,minflow;
const int INF=0x7fffffff/1000;

int bfs(int s)
{
    queue
<int> Q;
    Q.push(s);
    visit[s]
=true;
    
while(Q.size())
    {
         
int v=Q.front(); Q.pop();
         
if(v==n)return true ; 
         
for(int i=1; i<=n; i++)
                 
if(!visit[i]&&map[v][i]>0&&!visit[n])
                 {  
                     pre[i]
=v;
                     visit[i]
=true;
                     minflow
=minflow>map[v][i]?map[v][i]:minflow;
                     Q.push(i);
                 }
                   
    }
    
return false;
}

int maxflow()
{
    
int maxf=0;
    
while(1)
    {
           memset(pre,
0,sizeof pre);
           minflow
=INF;
           memset(visit,
0,sizeof visit);
           pre[
1]=-1;
           
if(bfs(1))
           {
                     
int inc=minflow;
                     
int t=n;
                     
while(pre[t]!=-1)
                     {
                          
int qq=pre[t];
                          map[qq][t]
-=inc;
                          map[t][qq]
+=inc;
                          t
=qq;
                     }
                     maxf
+=inc;
           }
           
else break;
    }
    
return maxf;
}

int main()
{
    
while(cin>>m>>n)
    {
       
int s,t,c;
       memset(map,
0,sizeof map);
       
while(m--)
       {
                cin
>>s>>t>>c;
                map[s][t]
+=c; 
       }               
       cout
<<maxflow()<<endl;
    }
    
   system(
"pause");
   
return 0;   
}

闂鎴栬灝卞嚭鐜板湪鍙栨渶灝忓肩殑闂涓婏紝涓嶈繃鎴戣涓哄墠涓ょ姣忔鍙栫殑鍙兘涓嶆槸鏈灝忕殑錛屼絾搴旇鏄病閿欑殑銆?br>鏈澶氬dfs鎴朾fs鍑犳銆?br>
#include<iostream>
#include
<string.h>
using namespace std;
int map[250][250];
int pre[250],q[250];
bool visit[250];
int m,n;
const int INF=0x7fffffff;

bool dfs(int v)
{
    visit[v]
=true;
    
if(v==n)return true;
    
for(int i=1; i<=n; i++)
            
if(map[v][i]>0&&!visit[i])
              { 
                  pre[i]
=v;
                  q[i]
=q[v]>map[v][i]?map[v][i]:q[v];
                  
if(dfs(i))return true;
              }
    
return 0;
}

int maxflow()
{
    
int maxf=0;
    
while(1)
    {
           memset(pre,
0,sizeof pre);
           memset(q,
0,sizeof q);
           
//for(int i=1; i<=n; i++)
                   q[1]=INF;
           memset(visit,
0,sizeof visit);
           pre[
1]=-1;
           
if(dfs(1))
           {
                    
                     
int inc=q[n];
                     
int t=n;
                     
while(pre[t]!=-1)
                     {
                          
int qq=pre[t];
                          map[qq][t]
-=inc;
                          map[t][qq]
+=inc;
                          t
=qq;
                     }
                     maxf
+=inc;
           }
           
else break;
    }
    
return maxf;
}

int main()
{
    
while(cin>>m>>n)
    {
       
int s,t,c;
       memset(map,
0,sizeof map);
       
while(m--)
       {
                cin
>>s>>t>>c;
                map[s][t]
+=c; 
       }               
       cout
<<maxflow()<<endl;
    }
    
   system(
"pause");
   
return 0;   
}


鐢板叺 2010-08-25 15:30 鍙戣〃璇勮
]]>
poj 3268 Silver Cow Party 銆愪袱嬈ijstra銆?/title><link>http://www.shnenglu.com/tianlearn-language/archive/2010/08/19/123925.html</link><dc:creator>鐢板叺</dc:creator><author>鐢板叺</author><pubDate>Thu, 19 Aug 2010 01:38:00 GMT</pubDate><guid>http://www.shnenglu.com/tianlearn-language/archive/2010/08/19/123925.html</guid><wfw:comment>http://www.shnenglu.com/tianlearn-language/comments/123925.html</wfw:comment><comments>http://www.shnenglu.com/tianlearn-language/archive/2010/08/19/123925.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/tianlearn-language/comments/commentRss/123925.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/tianlearn-language/services/trackbacks/123925.html</trackback:ping><description><![CDATA[棰樻剰錛?br>             灝辨槸浠庡悇鐐瑰埌X鐨勬渶鐭窛紱誨強浠嶺鍒板悇鐐圭殑鏈鐭窛紱誨拰鐨勬渶澶у箋?br><br>絎竴鍒╃敤dijstra姹傚嚭浠嶺鍒板悇鐐圭殑鏈鐭窛紱匯?br><br>鐒跺悗鎵鏈夌殑杈瑰弽鍚戯紝鍐嶈繘琛屼竴嬈ijstra姹俋鍒板悇鐐圭殑鏈鐭礬寰勩?br><br>絎簩嬈℃眰鍑虹殑鏈鐭礬寰勪篃灝辨槸鍚勭偣鍒癤鐨勬渶鐭礬寰勶紝鍥犱負杈瑰凡緇忓弽鍚戯紝瀵逛簬絎簩嬈′粠X鍒板悇鐐圭殑鏈鐭礬寰勬鏄?br>鍘熷浘浠庡悇鐐瑰埌X鐨勬渶鐭礬寰勩?br><br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; FONT-FAMILY: courier new; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br>#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">queue</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> INF</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0x7fffffff</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> map[</span><span style="COLOR: #000000">1001</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">1001</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> d[</span><span style="COLOR: #000000">1001</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">},N,M,X;<br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> dd[</span><span style="COLOR: #000000">1001</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">{</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">};<br></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000"> f[</span><span style="COLOR: #000000">1001</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> dijstra()<br>{<br>     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>             d[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;<br>     d[X]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>     memset(f,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000"> f);<br>     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>     {<br>             </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF,u</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d[j]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">min</span><span style="COLOR: #000000">&&!</span><span style="COLOR: #000000">f[j])<br>                     {<br>                                 min</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d[j];<br>                                 u</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">j;<br>                     }<br>             f[u]</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br>             </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>             {<br>                     </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d[u]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">map[u][j]</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">d[j])<br>                        d[j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d[u]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">map[u][j];<br>             }<br>     }<br>     <br>}<br><br></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> traverse()<br>{<br>     </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> temp;<br>     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">i; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>     {<br>             temp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> map[i][j];<br>             map[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">map[j][i];<br>             map[j][i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">temp;<br>     }<br>}<br><br></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br>{<br><br>    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">N</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">M</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">X;<br>    <br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>            map[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">INF;<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,s,t,value; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">M; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>    {<br>          cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">t</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">value;<br>          map[s][t]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">value;<br>    }<br>    <br>    dijstra();<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>             dd[i]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d[i]; <br>            <br>    traverse();<br>    dijstra();<br>    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">N; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(d[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dd[i]</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">max)max</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">d[i]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">dd[i];<br>    <br>    cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">max</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br>    <br>    system(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">pause</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br>    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>}<br></span></div> <img src ="http://www.shnenglu.com/tianlearn-language/aggbug/123925.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/tianlearn-language/" target="_blank">鐢板叺</a> 2010-08-19 09:38 <a href="http://www.shnenglu.com/tianlearn-language/archive/2010/08/19/123925.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>AOJ--The Max Weight--Floyd Folyd綆楁硶鍙樺艦錛屾妸姹傛渶鐭礬寰勭殑鍜屾敼涓烘眰鏈澶ц澆閲嶉噺鐨勯棶棰?/title><link>http://www.shnenglu.com/tianlearn-language/archive/2010/05/29/116704.html</link><dc:creator>鐢板叺</dc:creator><author>鐢板叺</author><pubDate>Sat, 29 May 2010 14:03:00 GMT</pubDate><guid>http://www.shnenglu.com/tianlearn-language/archive/2010/05/29/116704.html</guid><wfw:comment>http://www.shnenglu.com/tianlearn-language/comments/116704.html</wfw:comment><comments>http://www.shnenglu.com/tianlearn-language/archive/2010/05/29/116704.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/tianlearn-language/comments/commentRss/116704.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/tianlearn-language/services/trackbacks/116704.html</trackback:ping><description><![CDATA[<div id="3lb5hbn" class=BigTitle align=center>The Max Weight</div> <div id="hthh3jj" class=Limits align=center>Time Limit: 1000 ms   Memory Limit: 64 MB<br>Total Submission: 36   Accepted: 4 </div> <div id="h5vj3jr" class=Special align=center></div> <div id="lf3t3z3" class=ProblemTitle>Description</div> <div id="3r55xnf" class=ProblemContent>There a lot of bridges connect different positions in Venice,but they can't carry too much weigh,so each of them has a limit which can be described as an interger.A man wants to carry some goods from positon 1 to n.Help him find how much can he carry.</div> <br> <div id="5rzlpt5" class=ProblemTitle>Input</div> <div id="j5x35jt" class=ProblemContent>There are T cases.<br>For each case,the number of positions ( 1 < = n < = 100) and number m of bridges are exhibited on the first line.The following m lines contain triples of integers specifying start and end positions of the bridge and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one bridge between each pair of crossings.</div> <br> <div id="zlhdp5b" class=ProblemTitle>Output</div> <div id="blpvhl5" class=ProblemContent>The output for every scenario begins with a line containing "Case #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that the man can transport. Terminate the output for the scenario with a blank line.</div> <br> <div id="j35zhlx" class=ProblemTitle>Sampel Input</div> <div id="jf3t5jt" class=IO>1<br>3 3<br>1 2 3<br>1 3 4<br>2 3 5 </div> <br> <div id="vxtptfp" class=ProblemTitle>Sample Output</div> <div id="33znzbj" class=IO>Case #1:<abbr>[EOL]</abbr><br>4<abbr>[EOF]</abbr></div> <br>棰樻剰錛?br>n涓偣錛屾湁浜涚偣闂存湁妗ワ紝妗ヤ笂鏈夋渶澶ф壙閲嶉噺錛岄棶浣犱粠1鍒皀鍙互鏈澶ф惡甯︾殑鐗╁搧鐨勯噸閲忋?br>棰樿В錛?nbsp;<br> Folyd綆楁硶鍙樺艦錛屾妸姹傛渶鐭礬寰勭殑鍜屾敼涓烘眰鏈澶ц澆閲嶉噺鐨勯棶棰橈紝鍏抽敭鏄痙is[i][j]=dis[i][j]>dis[i][k]+dis[k][j]?dis[i][j]>dis[i][k]+dis[k][j]?:dis[i][j];鎹㈡垚dis[i][j]<span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(dis[i][j],min(dis[i][k],dis[k][j]));</span><br> <div style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; PADDING-BOTTOM: 4px; BACKGROUND-COLOR: #eeeeee; PADDING-LEFT: 4px; WIDTH: 98%; PADDING-RIGHT: 5px; FONT-FAMILY: courier new; FONT-SIZE: 14pt; WORD-BREAK: break-all; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid; PADDING-TOP: 4px"><span style="COLOR: #008080"> 1</span><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><span style="COLOR: #000000">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">cmath</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif">#include</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> std;<br></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000"> dis[</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">105</span><span style="COLOR: #000000">];<br></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #008080"> </span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Floyd(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> n)<br></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img id=Codehighlighter1_151_358_Open_Image onclick="this.style.display='none'; Codehighlighter1_151_358_Open_Text.style.display='none'; Codehighlighter1_151_358_Closed_Image.style.display='inline'; Codehighlighter1_151_358_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_151_358_Closed_Image onclick="this.style.display='none'; Codehighlighter1_151_358_Closed_Text.style.display='none'; Codehighlighter1_151_358_Open_Image.style.display='inline'; Codehighlighter1_151_358_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_151_358_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_151_358_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n; k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> j</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; j</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">n; j</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img id=Codehighlighter1_245_356_Open_Image onclick="this.style.display='none'; Codehighlighter1_245_356_Open_Text.style.display='none'; Codehighlighter1_245_356_Closed_Image.style.display='inline'; Codehighlighter1_245_356_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_245_356_Closed_Image onclick="this.style.display='none'; Codehighlighter1_245_356_Closed_Text.style.display='none'; Codehighlighter1_245_356_Open_Image.style.display='inline'; Codehighlighter1_245_356_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">     </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_245_356_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_245_356_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">       </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">j</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">dis[i][k]</span><span style="COLOR: #000000">&&</span><span style="COLOR: #000000">dis[k][j])<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">         dis[i][j]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">max(dis[i][j],min(dis[i][k],dis[k][j]));<br></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">     }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"><br></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/None.gif"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> main()<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img id=Codehighlighter1_372_710_Open_Image onclick="this.style.display='none'; Codehighlighter1_372_710_Open_Text.style.display='none'; Codehighlighter1_372_710_Closed_Image.style.display='inline'; Codehighlighter1_372_710_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_372_710_Closed_Image onclick="this.style.display='none'; Codehighlighter1_372_710_Closed_Text.style.display='none'; Codehighlighter1_372_710_Open_Image.style.display='inline'; Codehighlighter1_372_710_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedBlock.gif"></span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_372_710_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_372_710_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> t,i,j,m,n;<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">t;<br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> k</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">; k</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">t; k</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img id=Codehighlighter1_437_694_Open_Image onclick="this.style.display='none'; Codehighlighter1_437_694_Open_Text.style.display='none'; Codehighlighter1_437_694_Closed_Image.style.display='inline'; Codehighlighter1_437_694_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_437_694_Closed_Image onclick="this.style.display='none'; Codehighlighter1_437_694_Closed_Text.style.display='none'; Codehighlighter1_437_694_Open_Image.style.display='inline'; Codehighlighter1_437_694_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_437_694_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_437_694_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">25</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">m;<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      memset(dis,</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">sizeof</span><span style="COLOR: #000000"> (dis));<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> s,e,w; i</span><span style="COLOR: #000000"><=</span><span style="COLOR: #000000">m; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #000000"><img id=Codehighlighter1_539_600_Open_Image onclick="this.style.display='none'; Codehighlighter1_539_600_Open_Text.style.display='none'; Codehighlighter1_539_600_Closed_Image.style.display='inline'; Codehighlighter1_539_600_Closed_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="DISPLAY: none" id=Codehighlighter1_539_600_Closed_Image onclick="this.style.display='none'; Codehighlighter1_539_600_Closed_Text.style.display='none'; Codehighlighter1_539_600_Open_Image.style.display='inline'; Codehighlighter1_539_600_Open_Text.style.display='inline';" align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ContractedSubBlock.gif">      </span><span style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #ffffff; DISPLAY: none; BORDER-TOP: #808080 1px solid; BORDER-RIGHT: #808080 1px solid" id=Codehighlighter1_539_600_Closed_Text><img src="http://www.shnenglu.com/Images/dot.gif"></span><span id=Codehighlighter1_539_600_Open_Text><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        cin</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">s</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">e</span><span style="COLOR: #000000">>></span><span style="COLOR: #000000">w;<br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">        dis[s][e]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">dis[e][s]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">w;<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">      }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      <br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      Floyd(n);<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">      <br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">     cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Case #</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">k</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">dis[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">][n]</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br></span><span style="COLOR: #008080">37</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif">    }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/InBlock.gif">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img align=top src="http://www.shnenglu.com/Images/OutliningIndicators/ExpandedBlockEnd.gif">}</span></span></div> <img src ="http://www.shnenglu.com/tianlearn-language/aggbug/116704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/tianlearn-language/" target="_blank">鐢板叺</a> 2010-05-29 22:03 <a href="http://www.shnenglu.com/tianlearn-language/archive/2010/05/29/116704.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>USACO--AOJ Bessie Come Home --Floyd綆楁硶http://www.shnenglu.com/tianlearn-language/archive/2010/05/23/116182.html鐢板叺鐢板叺Sun, 23 May 2010 12:03:00 GMThttp://www.shnenglu.com/tianlearn-language/archive/2010/05/23/116182.htmlhttp://www.shnenglu.com/tianlearn-language/comments/116182.htmlhttp://www.shnenglu.com/tianlearn-language/archive/2010/05/23/116182.html#Feedback1http://www.shnenglu.com/tianlearn-language/comments/commentRss/116182.htmlhttp://www.shnenglu.com/tianlearn-language/services/trackbacks/116182.htmlBessie Come Home

Time Limit:JAVA/Others2000/1000MS  Memory Limit:JAVA/Others131072/65536KB
Total Submit:6 Accepted:2

Description

It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow).

Between milkings, each cow is located in her own pasture, though some pastures have no cows in them. Each pasture is connected by a path to one or more other pastures (potentially including itself). Sometimes, two (potentially self-same) pastures are connected by more than one path. One or more of the pastures has a path to the barn. Thus, all cows have a path to the barn and they always know the shortest path. Of course, cows can go either direction on a path and they all walk at the same speed.

The pastures are labeled `a'..`z' and `A'..`Y'. One cow is in each pasture labeled with a capital letter. No cow is in a pasture labeled with a lower case letter. The barn's label is `Z'; no cows are in the barn, though.

Input

Line 1: Integer P (1 <= P <= 10000) the number of paths that interconnect the pastures (and the barn)
Line 2..P+1: Space separated, two letters and an integer: the names of the interconnected pastures/barn and the distance between them (1 <= distance <= 1000)

Output

A single line containing two items: the capital letter name of the pasture of the cow that arrives first back at the barn, the length of the path followed by that cow.

Sample Input

5
A d 6
B d 3
C e 9
d Z 8
e Z 3

Sample Output

B 11

 1Floyd 綆楁硶錛?a >http://icpc.ahu.edu.cn:8080/AOJ/   鍋氱殑絎竴涓浘璁洪
 2鍥劇殑鏈鐭礬寰勯棶棰橈紝鍒?#8216;Z’鐨勬渶鐭礬寰勶紱
 3Floyd綆楁硶澶ф鐭ラ亾鎬庝箞鐢ㄤ簡 錛屽ソ鍍忔槸鍔ㄦ佽鍒掑疄鐜扮殑錛屼笉鐭ラ亾涓轟粈涔堣繖鏍鋒槸瀵圭殑
 4O錛圢^3錛夋眰瑙f渶鐭礬寰勯棶棰橈紝鏁版嵁鑼冨洿瓚呰繃400鍙兘灝卞嵄闄╀簡
 5#include<iostream>
 6#include<string.h>
 7using namespace std;
 8int dis[53][53];
 9const int INF=10000000;
10void Floyd(int n)
11{
12     for(int k=1; k<=n; k++)
13     for(int i=1; i<=n; i++)
14     for(int j=1; j<=n; j++)
15      if(i!=k&&k!=j&&i!=j&&dis[i][k]+dis[k][j]<dis[i][j])
16      dis[i][j]=dis[i][k]+dis[k][j];
17
18}

19
20
21int main()
22{
23    int p,i,j,k,d,n1,n2; 
24    cin>>p;
25    memset(dis,0,sizeof (dis));
26    for(i=1; i<=52; i++)
27    for(j=1; j<=52; j++)
28    dis[i][j]=INF;
29     
30    for(i=1; i<=p; i++)
31    {
32       char v1,v2;
33       cin>>v1>>v2>>d;      
34       if(v1==v2)continue;
35       n1=(v1>='a'?v1-'a'+1:v1-'A'+26+1);
36       n2=(v2>='a'?v2-'a'+1:v2-'A'+26+1);
37       if(d<dis[n1][n2])dis[n1][n2]=dis[n2][n1]=d;
38    }

39    
40    Floyd(52);
41    
42    int min=INF+100;
43    char c;
44    for(i=27; i<=51; i++//澶у啓瀛楁瘝鍒癦 
45    {
46       if(dis[i][52]<min){min=dis[i][52];c=i; }
47    }

48    cout<<char(c-27+'A')<<' '<<min<<endl;
49    //system("pause");
50    return 0;
51}

52



鐢板叺 2010-05-23 20:03 鍙戣〃璇勮
]]>
精品久久久无码21p发布| 日韩一区二区久久久久久| 久久精品国产亚洲综合色| 伊人久久大香线蕉av不变影院| 久久国产视频网| 一级a性色生活片久久无| 亚洲精品美女久久久久99小说| 热久久国产欧美一区二区精品 | 久久93精品国产91久久综合| 久久国产精品久久国产精品| 国产精品久久久天天影视| 久久不射电影网| 久久国产视屏| 久久久久亚洲av综合波多野结衣| 久久精品免费全国观看国产| 久久精品国产亚洲AV香蕉| a级成人毛片久久| 久久中文字幕视频、最近更新 | 无码国内精品久久人妻麻豆按摩 | 996久久国产精品线观看| 国产一级持黄大片99久久 | 国产亚洲色婷婷久久99精品91| 久久久久国产| 麻豆成人久久精品二区三区免费| 久久精品国产亚洲av水果派| 精品久久久久久国产免费了| 久久久久久综合网天天| 久久精品国产亚洲麻豆| 久久亚洲2019中文字幕| 亚洲AV无码久久精品成人 | 久久综合一区二区无码| 无码国内精品久久人妻蜜桃 | 久久精品中文字幕大胸| 国产精品美女久久久久网| 色天使久久综合网天天| 久久99热只有频精品8| 久久免费视频6| 久久精品一区二区| 色欲久久久天天天综合网| 久久久久人妻精品一区三寸蜜桃| 欧美黑人激情性久久|