设为首页 加入收藏

TOP

poj1613Cave Raider(带限制的最短路+spfa)(二)
2015-07-20 17:49:43 来源: 作者: 【 】 浏览:15
Tags:poj1613Cave Raider 限制 短路 spfa
ut

16
55
*

Source

Asia Kaohsiung 2003

代码:

#include
      
       
#include
       
         #include
        
          #include
         
           #include
          
            #include
           
             #define INF 0x3f3f3f3f using namespace std; const int maxn=50+10; int dis[maxn]; int n,m,st,en; bool vis[maxn]; struct Edge { int to,time; vector
            
             door; }; vector
             
              vec[maxn]; void read_graph() { char s[100+10]; for(int i=0;i
              
               ='0'&&s[i]<='9') x=x*10+s[i]-'0'; else { now.door.push_back(x); x=0; } } now.door.push_back(x); now.door.push_back(INF); now.to=u; vec[v].push_back(now); now.to=v; vec[u].push_back(now); } } void Spfa() { queue
               
                Q; while(!Q.empty()) Q.pop(); memset(dis,0x3f,sizeof(dis)); memset(vis,false,sizeof(vis)); dis[st]=0; vis[st]=true; Q.push(st); while(!Q.empty()) { int temp=Q.front(); vis[temp]=false; Q.pop(); for(int i=0;i
                
                 time+real_time) { dis[next]=time+real_time; if(!vis[next]) { vis[next]=true; Q.push(next); } } break; } } } } if(dis[en]==INF) printf("*\n"); else printf("%d\n",dis[en]); } int main() { while(~scanf("%d",&n)) { if(n==0) return 0; read_graph(); Spfa(); } return 0; } 
                
               
              
             
            
           
          
         
        
       
      



首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 1222 EXTENDED LIGHTS OUT(.. 下一篇C++11之 unique_ptr

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C语言中如何将结构体 (2025-12-24 22:20:09)
·纯C语言结构体成员变 (2025-12-24 22:20:06)
·C语言中,指针函数和 (2025-12-24 22:20:03)
·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)