HDU 1535 Invitation Cards (POJ 1511)

Source: Internet
Author: User

SPFA twice. Calculates the sum of the least short circuit between the come and the return.

Using Dijkstra + adjacent matrix is indeed easy to write + easy to exchange, but there are 1000000 points, and the matrix cannot be opened.


D1 [] is 1 ~ N.

Swap the neighboring points of all edges.

D2 [] is 1 ~ N.


All are added as the desired answer.

Sadly, SPFA "HDU 1535" AC is used, but POJ 1511 is the same as POJ.


Then the obsessive-compulsive disorder keeps testing.


Prices are positive integers the sum of which is smaller than 1000000000

Int can be used. HDU is like this.

Then I changed the sum of POJ to long. Or WA.

Then I found that there was a problem with INF, and 0 xfffffff was not enough. Then change it to the maximum value of 0x7fffff int, AC.

POJ data is awesome. I do not want to read the question at all.


#include
 
  #include
  
   #include
   
    #include
    
     #include#include
     
      #include
      #include
       
        #include
        
         #include
         
          #include
          
           #include
           
            #define INF 0x7fffffff#define eps 1e-6using namespace std;int n,m;struct lx{ int v,d;};int dis[1000001];bool vis[1000001];int e[1000001];vector
            
             g[1000001];void swapg(){ for(int i=1;i<=n;i++) e[i]=g[i].size(); for(int i=1;i<=n;i++) { int u,v,d; lx now; u=i; for(int j=0;j
             
              q; dis[1]=0,vis[1]=1; q.push(1); while(!q.empty()) { int u=q.front();q.pop(); vis[u]=0; for(int j=e[u];j
              
               dis[u]+d) { dis[v]=dis[u]+d; if(!vis[v]) { vis[v]=1; q.push(v); } } } } int ans=0; //long long for(int i=1;i<=n;i++) ans+=dis[i]; return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int u,v,d; lx now; for(int i=1;i<=n;i++) g[i].clear(); while(m--) { scanf("%d%d%d",&u,&v,&d); now.d=d; now.v=v; g[u].push_back(now); } memset(e,0,sizeof(e)); int dis1=SPFA(n); //long long swapg(); int dis2=SPFA(n); //long long printf("%d\n",dis1+dis2); // lld% }}
              
             
            
           
          
         
        
       
     
    
   
  
 




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.