锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产一区二区三区不卡在线观看,久久免费精品视频,欧美一级视频精品观看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絎竴嬈″啓嬈″皬鐢熸垚鏍?wèi)锛屾病鎯冲?/div>
鎬濇兂灝辨槸錛氭眰涓嬈℃渶灝忕敓鎴愭爲(wèi)錛岃褰曟墍鐢ㄥ埌鐨勮竟錛岀劧鍚庝笉鐢ㄦ墍鏈夌涓嬈$敤鍒扮殑杈瑰皾璇曟瀯鎴愭瀯鎴愭渶灝忕敓鎴愭爲(wèi)銆?/div>
鐢↘ruskal鍏堟眰鏈灝忕敓鎴愭爲(wèi)錛岀粨鏋滃嵆涓簃in錛屾妸鎵鐢ㄥ埌鐨勮竟璁板綍涓嬫潵錛堣繖閲屾槸璁板綍鐨勫搴旂殑涓嬭〃錛夛紝鐒跺悗鏋氫婦榪欎簺杈癸紝
姣忔鍘繪帀涓涓竟姹備竴嬈℃渶灝忕敓鎴愭爲(wèi)錛岀粨鏋滀負(fù)tmin錛屽鏋滆兘澶熸垚鏈灝忕敓鎴愭爲(wèi)騫朵笖tmin==min錛屽垯璇存槑鏈灝忕敓鎴愭爲(wèi)涓嶅敮涓
#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 絎竴嬈℃眰鏈灝忕敓鎴愭爲(wèi)錛宨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)//絎竴嬈℃渶灝忕敓鎴愭爲(wèi)鐨勬椂鍊欐妸location緗負(fù)-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 

浠庢瘡涓墰寮濮嬫眰涓嬈″崟婧愭渶鐭礬寰勶紝鍋囪璧風(fēng)偣鏄疿錛屽鏋滀粠X鑳藉埌i (di[i]!=INF) 錛宑nt[i]++錛岀敤鏉ョ粺璁¤兘鍒拌揪 i 鐐圭殑鐗涚殑鏁伴噺銆?br>
緇撴灉灝辨槸婊¤凍cnt[i]==K鐨勬暟閲忥紝鍗砳鐐規(guī)墍鏈夌殑鐗涢兘鍙互鍒拌揪銆?br>
鐢╯pfa姹傦紝spfa鍦ㄨ繖閲屼笉鏄眰鏈孌佃礬寰勶紝鍙鍒頒簡(jiǎn)灝辮錛屼笉闇瑕佹槸鏈鐭殑錛屽洜姝や細(xì)鏇村揩涓鐐廣?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
浜屽垎鍥劇殑鏈澶у尮閰嶏紝鍔犱竴涓簮鐐癸紝榪欎釜婧愮偣鍒板乏杈規(guī)墍鏈夐《鐐瑰姞涓鏉¤竟錛屾潈鍊間負(fù)1. 銆傚悓鐞嗭紝鍔犱竴涓粓鐐癸紝鎵鏈夊彸杈圭殑瀹氱偣鍒拌繖涓粓鐐規(guī)湁鏉¤竟錛屾潈鍊間負(fù)1. 榪欐牱浜屽垎鍥劇殑鏈澶у尮閰嶅氨杞崲鎴愪簡(jiǎn)鏈澶ф祦闂銆?/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>
         鍙戠幇鐪嬩唬鐮佹湁鏃跺欐瘮鐪嬩功鏇村鏄撴噦錛岀湅鏈澶ф祦宸茬粡鐪嬩簡(jiǎn)濂藉嚑澶╀功浜?jiǎn)锛岄兘鏄檿涔庝箮鐨勫Q屽弬鑰冧簡(jiǎn)涓涓嬪埆浜虹殑浠g爜錛屼技涔庢湁浜涗簡(jiǎn)瑙d簡(jiǎn)銆?br>
      Ford-Fulkerson鏂規(guī)硶鐨勫騫胯礬綆楁硶
      姣忔鐢╠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鐨勬渶鐭窛紱誨強(qiáng)浠嶺鍒板悇鐐圭殑鏈鐭窛紱誨拰鐨勬渶澶у箋?br><br>絎竴鍒╃敤dijstra姹傚嚭浠嶺鍒板悇鐐圭殑鏈鐭窛紱匯?br><br>鐒跺悗鎵鏈夌殑杈瑰弽鍚戯紝鍐嶈繘琛屼竴嬈ijstra姹俋鍒板悇鐐圭殑鏈鐭礬寰勩?br><br>絎簩嬈℃眰鍑虹殑鏈鐭礬寰勪篃灝辨槸鍚勭偣鍒癤鐨勬渶鐭礬寰勶紝鍥犱負(fù)杈瑰凡緇忓弽鍚戯紝瀵逛簬絎簩嬈′粠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="hvzpftn" class=BigTitle align=center>The Max Weight</div> <div id="hvzpftn" class=Limits align=center>Time Limit: 1000 ms   Memory Limit: 64 MB<br>Total Submission: 36   Accepted: 4 </div> <div id="hvzpftn" class=Special align=center></div> <div id="hvzpftn" class=ProblemTitle>Description</div> <div id="hvzpftn" 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="hvzpftn" class=ProblemTitle>Input</div> <div id="hvzpftn" 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="hvzpftn" class=ProblemTitle>Output</div> <div id="hvzpftn" 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="hvzpftn" class=ProblemTitle>Sampel Input</div> <div id="hvzpftn" class=IO>1<br>3 3<br>1 2 3<br>1 3 4<br>2 3 5 </div> <br> <div id="hvzpftn" class=ProblemTitle>Sample Output</div> <div id="hvzpftn" 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綆楁硶澶ф鐭ラ亾鎬庝箞鐢ㄤ簡(jiǎn) 錛屽ソ鍍忔槸鍔ㄦ佽鍒掑疄鐜扮殑錛屼笉鐭ラ亾涓轟粈涔堣繖鏍鋒槸瀵圭殑
 4O錛圢^3錛夋眰瑙f渶鐭礬寰勯棶棰橈紝鏁版嵁鑼冨洿瓚呰繃400鍙兘灝卞嵄闄╀簡(jiǎn)
 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 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
              国产精品美女久久久免费| 99视频国产精品免费观看| 美女国产一区| 国产精品成人v| 亚洲国产精品va在看黑人| 国产欧美日韩在线视频| 一本色道久久综合精品竹菊| 亚洲国产日韩欧美在线图片 | 亚洲一区免费看| 免费在线欧美黄色| 久久久久久亚洲精品不卡4k岛国| 欧美午夜无遮挡| 亚洲精品视频在线观看网站| 亚洲国产精品一区二区第四页av| 欧美一级大片在线观看| 亚洲欧美日韩第一区| 欧美日韩精品一区二区| 亚洲高清视频一区| 亚洲黄一区二区三区| 久久亚洲午夜电影| 久久综合电影| 一区福利视频| 久久精品一区二区三区不卡| 久久久久国产精品人| 国产视频一区二区三区在线观看| 亚洲性感激情| 欧美一区二区三区视频在线| 国产裸体写真av一区二区| 亚洲少妇自拍| 欧美亚洲一区二区三区| 国产伦精品一区二区三区四区免费| 中文亚洲字幕| 香蕉久久久久久久av网站| 国产精品自拍小视频| 久久成人亚洲| 久久亚洲国产精品一区二区| 亚洲电影视频在线| 欧美+日本+国产+在线a∨观看| 亚洲成人资源网| 99热精品在线观看| 欧美日韩伊人| 午夜伦欧美伦电影理论片| 久久精品二区| 亚洲国产乱码最新视频| 欧美二区在线播放| 日韩视频一区二区| 小嫩嫩精品导航| 一区二区在线视频播放| 欧美高清视频一二三区| 一区二区av在线| 久久精品国产清高在天天线| 加勒比av一区二区| 欧美激情一区二区| 亚洲综合欧美日韩| 欧美大学生性色视频| 在线性视频日韩欧美| 国产精品视频yy9099| 久久久久久久尹人综合网亚洲| 亚洲第一福利视频| 亚洲综合视频一区| 精品成人一区二区三区四区| 欧美福利在线| 午夜亚洲福利在线老司机| 欧美高清在线精品一区| 亚洲专区在线| 亚洲国产成人91精品| 国产精品高潮呻吟久久av无限| 久久精品99国产精品日本| 91久久精品日日躁夜夜躁国产| 亚洲欧美日韩天堂| 亚洲国产网站| 国产亚洲精品久久飘花| 欧美精品在线播放| 久久aⅴ国产欧美74aaa| 亚洲美女在线视频| 久久综合网络一区二区| 亚洲视频在线看| 亚洲国产欧美精品| 国产午夜亚洲精品羞羞网站 | 国产午夜精品视频| 欧美日本高清视频| 久久一二三四| 先锋影音网一区二区| 亚洲精品女人| 久久久久国产精品午夜一区| 亚洲尤物影院| av成人激情| 亚洲国产精品ⅴa在线观看| 国产精自产拍久久久久久蜜| 欧美日本中文字幕| 老司机午夜免费精品视频| 亚洲欧美中文日韩在线| 日韩一区二区免费看| 亚洲二区在线| 欧美二区乱c少妇| 久久天堂av综合合色| 午夜精品一区二区三区在线 | 久久亚洲午夜电影| 欧美在线999| 亚洲欧美激情四射在线日 | 亚洲精品一二| 亚洲精品国产精品乱码不99| 欧美大色视频| 欧美激情第三页| 久久综合久久美利坚合众国| 小嫩嫩精品导航| 欧美一区二区三区男人的天堂| 一片黄亚洲嫩模| 在线亚洲一区观看| 一区二区欧美日韩| 亚洲一级黄色片| 亚洲欧美在线一区二区| 亚洲免费婷婷| 午夜一区不卡| 久久久午夜精品| 久久综合网络一区二区| 欧美成人午夜剧场免费观看| 免费在线看一区| 欧美成人日韩| 亚洲美女少妇无套啪啪呻吟| 亚洲乱码一区二区| 艳妇臀荡乳欲伦亚洲一区| 亚洲一二三区在线观看| 午夜精品一区二区三区电影天堂 | 国产一区观看| 亚洲第一成人在线| 99re6这里只有精品| 亚洲天堂成人在线视频| 午夜一级久久| 欧美成人高清| 99精品视频一区| 欧美亚洲免费高清在线观看| 久久精品91| 欧美激情91| 国产精品一级在线| 伊人久久大香线蕉综合热线 | 久久一综合视频| 亚洲成人资源网| 亚洲女人天堂av| 六月丁香综合| 国产精品视频免费观看| 狠狠爱综合网| 亚洲婷婷在线| 久久综合一区二区三区| 亚洲精品美女在线| 久久激情视频免费观看| 欧美国产精品劲爆| 国产日韩欧美在线一区| 亚洲欧洲精品一区二区三区不卡| 亚洲在线观看视频| 欧美www在线| 午夜精品婷婷| 欧美日韩国产精品专区| 狠狠干综合网| 亚洲字幕在线观看| 亚洲高清视频一区二区| 亚洲夜间福利| 欧美日韩国产首页| 尤妮丝一区二区裸体视频| 亚洲影院免费| 亚洲高清激情| 久久综合图片| 国产亚洲日本欧美韩国| 亚洲午夜在线观看| 亚洲成人在线视频播放 | 在线性视频日韩欧美| 另类av导航| 亚洲欧美日韩国产综合精品二区| 欧美激情精品久久久久久黑人 | 亚洲综合色激情五月| 亚洲国产精品悠悠久久琪琪| 欧美一区二区三区在线播放| 国产精品福利在线观看网址| 亚洲精品视频免费| 欧美成人精品激情在线观看| 欧美一级黄色网| 国产精品视频大全| 亚洲综合色在线| 一区二区高清在线| 欧美日韩久久精品| 亚洲美女性视频| 亚洲黄色免费网站| 噜噜噜躁狠狠躁狠狠精品视频| 精久久久久久| 久热爱精品视频线路一| 欧美亚洲自偷自偷| 国产日韩精品一区二区| 午夜精品久久久久久| 一区二区国产日产| 欧美午夜电影网| 亚洲一区二区三区色| 一本久久a久久精品亚洲| 欧美日韩精品综合| 一区二区高清在线观看| 99国内精品久久| 欧美性猛交一区二区三区精品| 亚洲天堂av在线免费| 亚洲图片欧美午夜| 国产精品免费看| 久久久www成人免费精品|