POJ2662-AWalkThroughtheForest (shortest circuit + memory search)

Source: Internet
Author: User
Question link:

Question link: Portal

The question is very important ..

The number of paths from the start point to the end point as required. For any two points A and B, the condition that A can go from A to B is that there is A path from B to the end of the length less than any one A to the end of the road, that is, the minimum short circuit from B to the end is smaller than that from A to the end. Why? Think about it. now we need to find A path in the path from B to the end to ensure that its length is smaller than the shortest path from A to the end (think about it and try any two words ), therefore, when the short circuit from B to the end meets the above conditions, the first condition is met. (Because if the shortest path from B to the end cannot be smaller than any path from A to the end, the other path will not be satisfied ..)

Then there is the number of dfs search paths ..

#include #include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           #include 
            
             #define ll long long#define maxn 1010#define pp pair
             
              #define INF 0x3f3f3f3f#define max(x,y) ( ((x) > (y)) ? (x) : (y) )#define min(x,y) ( ((x) > (y)) ? (y) : (x) )using namespace std;vector < pp > eg[maxn];int n,m,dis[maxn],dp[1010];bool vis[1010];void spfa(){queue 
              
                Q;memset(vis,0,sizeof(vis));memset(dis,INF,sizeof(dis));dis[2]=0;Q.push(2);while(!Q.empty()){int u=Q.front();Q.pop();vis[u]=0;for(int i=0;i
               
                dis[u]+w){dis[v]=dis[u]+w;if(!vis[v]){vis[v]=1;Q.push(v);}}}}}int dfs(int u){if(u==2)return 1;if(dp[u]>=0)return dp[u];dp[u]=0;for(int i=0;i
                
                 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.