Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:43+00:00 2026-05-27T16:43:43+00:00

I am trying to implement a flow algorithm with thousands of nodes and edges,

  • 0

I am trying to implement a flow algorithm with thousands of nodes and edges, therefore I need efficient data structures. Currently I do the following:

Structure Node:

Double Linked Array (Parents) //Edges that enter the node (basicaly a tuple that contains a pointer to the parent node and the weight, current flow of the edge
Double Linked Array (Sons) //Edges that leave the node

The problem is, when I perform a BFS, given a node v I need to look at the edges in the residual graph (basically backwards edges for the edges you send flow on), that leave v. Because I can have parallel edges I need to always know which backwards edge comes from which forward edge.

Currently I am solving the problem by first handling all edges in Sons(v), and then I defined a map that gives me the index of the Parents(w) in the destination node w of all those edges. Therefore I get the backwards edge I stored and can perform my algorithm. However those maps have log(E) access time which slows my algorithm down way too much. How should I approach this problem (the double linked lists are implemented as std::vector)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:43:44+00:00Added an answer on May 27, 2026 at 4:43 pm

    The representation I use is something like an edge list but with additional information

    typedef long long dintype;
    struct edge{
      edge(int t_ = 0,int n_ = 0, dintype c_ = 0){
        to = t_;
        next = n_;
        cap = c_;
      }
      int to,next;
      dintype cap;
    };
    const int max_edges = 131010;
    const int max_nodes = 16010;
    edge e[max_edges];
    int first[max_nodes]; // initialize this array with -1
    int edges_num;
    inline void add_edge(int from,int to, dintype cap){
      if(edges_num == 0){
        memset(first,-1,sizeof(first));
      }
      e[edges_num].to = to;e[edges_num].cap = cap;
      e[edges_num].next = first[from];first[from] = edges_num++;
    
      e[edges_num].to = from;e[edges_num].cap = 0;
      e[edges_num].next = first[to];first[to] = edges_num++;
    }
    

    I have used global arrays to be able to explain the idea better. I use this for my dinitz algorithm.

    Now a bit of explanation. In the array "e" I hold all the edges. In the array first[v] I hold the index of the first edge going out of v in the array e. If an edge is present in index idx in the array e then the reverse edge is stored in the element with index idx^1.
    So this representation enables us to both have a neighbours list(strarting from first[v] and following the next index until it becomes -1) and be able to access the reverse edge in constant time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement the Ford-Fulkerson algorithm to compute the maximum flow in a
All I am currently trying implement something along the lines of dim l_stuff as
I am currently trying to write an algorithm that determines how many bits are
I am trying to implement content flow in my zf application. And while loading
I'm trying implement Data Annotation to my Linq to SQL objects. The .dbml file
I'm trying to implement the Ford Fulkerson Algorithm in C++. However, I'm having trouble
I'm trying to implement a way to trigger a request for map overlay data
I am trying to implement a 'git-flow' kind of workflow using Gerrit but I
I am trying implement the Data transformation using Reflection 1 example in my code.
I'm trying to implement a FUSE-driven filesystem in Python, which serves data from both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.