锘??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>
              久久人人爽人人爽爽久久| 免费视频最近日韩| 亚洲一区二区在线观看视频| 亚洲精美视频| 欧美成人高清| 日韩网站免费观看| 一本色道88久久加勒比精品 | 国产午夜精品全部视频在线播放 | 欧美国产乱视频| 亚洲欧洲日本专区| 亚洲精品一区二区三区在线观看 | 亚洲三级观看| 欧美日韩视频在线一区二区观看视频| 国产精品视频yy9099| 欧美资源在线| 久久久精品性| 亚洲网站视频福利| 香蕉久久一区二区不卡无毒影院 | 久久久久成人网| 亚洲成人在线视频播放| 亚洲人成绝费网站色www| 国产精品豆花视频| 免费成人毛片| 欧美日韩在线一区二区三区| 久久精品国产91精品亚洲| 久久裸体艺术| 国产亚洲精久久久久久| 9久草视频在线视频精品| 亚洲欧美在线免费| 国产精品大片wwwwww| 久久久www免费人成黑人精品| 在线视频精品一区| 精品99视频| 亚洲午夜成aⅴ人片| 亚洲第一精品久久忘忧草社区| 久久久久九九视频| 午夜精品区一区二区三| 亚洲久色影视| 久久精品日产第一区二区三区| 国产欧美日韩一区| 久久精品国产综合| 欧美美女bbbb| 欧美黄在线观看| 久久夜色精品国产亚洲aⅴ| 亚洲在线视频| 欧美成人免费小视频| 久久精品国产99国产精品| 午夜宅男久久久| 亚洲一区二区三区影院| 亚洲欧美日韩精品久久| 国产精品一区二区久久久久| 亚洲国产婷婷香蕉久久久久久99| 欧美精品偷拍| 欧美激情国产日韩| 欧美理论在线| 欧美激情一区二区三区四区| 黄色成人av网| 久久精品免费观看| 久久久综合网站| 国产美女诱惑一区二区| 久久天天躁夜夜躁狠狠躁2022| 久久青草久久| 一本色道久久88综合亚洲精品ⅰ | 亚洲第一网站免费视频| 国产自产v一区二区三区c| 久热精品视频在线观看| 国产亚洲人成a一在线v站 | 在线观看精品| 久久久久天天天天| 久久一区二区三区超碰国产精品| 男人的天堂亚洲在线| 蜜臀a∨国产成人精品| 雨宫琴音一区二区在线| 久久先锋影音av| 欧美激情女人20p| 亚洲狼人综合| 欧美体内she精视频在线观看| 久久久久五月天| 伊人春色精品| 男人的天堂亚洲| 欧美在线在线| 国语自产精品视频在线看一大j8 | 欧美在线日韩| 美女图片一区二区| 国产精品久久久久9999吃药| 亚洲视屏在线播放| 久久久亚洲国产天美传媒修理工| 欧美另类一区二区三区| 一区二区三区欧美日韩| 欧美伊人久久久久久久久影院 | 亚洲自拍16p| 久久综合久久综合这里只有精品| 欧美网站在线观看| 午夜免费久久久久| 男人的天堂亚洲在线| 夜夜夜精品看看| 国产精品羞羞答答| 亚洲少妇诱惑| 久久综合狠狠| 一本色道久久综合一区| 免费视频一区| 亚洲天堂免费在线观看视频| 久久青草欧美一区二区三区| 国产精品萝li| 一本色道久久88亚洲综合88| 亚洲精选成人| 国产一区日韩二区欧美三区| 欧美承认网站| 亚洲福利国产精品| 欧美影院午夜播放| 亚洲人妖在线| 国内成人精品一区| 欧美日韩一区高清| 久热re这里精品视频在线6| 亚洲视频碰碰| 亚洲欧洲视频在线| 麻豆精品国产91久久久久久| 亚洲永久免费| 日韩视频中文| 亚洲电影自拍| 欧美电影免费观看大全| 欧美在线免费播放| 亚洲一区中文| 亚洲靠逼com| 欧美激情一区二区三区全黄| 久久婷婷成人综合色| 亚洲欧美视频在线观看视频| 亚洲精品美女免费| 最新日韩av| 亚洲国产成人久久| 欧美日韩国产在线播放网站| 久久中文在线| 久久精品99无色码中文字幕| 中国av一区| 99国产精品久久久久久久成人热 | 一区二区日韩| 亚洲日韩中文字幕在线播放| 黄色成人在线观看| 国产一区二区视频在线观看| 久久亚洲风情| 久久精精品视频| 欧美在线网址| 先锋a资源在线看亚洲| 亚洲男女自偷自拍| 午夜日本精品| 午夜亚洲影视| 久久av一区二区三区| 欧美中文字幕在线视频| 久久成人资源| 久久一本综合频道| 欧美大片专区| 欧美日韩精品免费观看| 欧美日韩综合网| 久久综合精品国产一区二区三区| 一级日韩一区在线观看| 一区二区日韩免费看| 亚洲午夜黄色| 久久aⅴ国产欧美74aaa| 欧美在线亚洲| 久久人人看视频| 欧美成人激情视频免费观看| 欧美激情免费观看| 欧美性猛交xxxx乱大交蜜桃| 国产精品日韩| 欧美巨乳波霸| 国产精品一区二区在线观看不卡| 欧美成人乱码一区二区三区| 欧美屁股在线| 国产精品中文在线| 狠狠色狠狠色综合人人| 国产精品午夜在线观看| 国内精品久久久久伊人av| 亚洲国产裸拍裸体视频在线观看乱了中文| 欧美日韩在线免费视频| 国产精品制服诱惑| 亚洲国产一区在线| 亚洲欧美高清| 免费一区二区三区| 99re66热这里只有精品3直播| 欧美不卡视频一区| 一区二区不卡在线视频 午夜欧美不卡在| 久久一区国产| 日韩视频在线观看一区二区| 亚洲免费在线观看视频| 亚洲无玛一区| 奶水喷射视频一区| 国产精品亚洲美女av网站| 在线日本成人| 亚洲欧美日本伦理| 欧美成人午夜| 欧美成年人在线观看| 亚洲一区二区三区视频| 一本久道综合久久精品| 夜夜精品视频| 卡一卡二国产精品| 国产精品永久免费观看| 国产农村妇女精品一二区| 亚洲人成啪啪网站| 久久久久99精品国产片| 亚洲天堂免费观看|