What should be the approach to find all paths with maximum flow? The graph is directed acyclic graph and the maximum number of nodes(vertices) in the graph can be 40 and edges around 80. Also, most of the edges have unit capacity.

# | User | Rating |
---|---|---|

1 | tourist | 3687 |

2 | ecnerwala | 3668 |

3 | Benq | 3503 |

4 | ksun48 | 3421 |

5 | Um_nik | 3412 |

6 | Radewoosh | 3382 |

7 | maroonrk | 3323 |

8 | ainta | 3318 |

9 | Itst | 3239 |

10 | apiadu | 3238 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 204 |

2 | SecondThread | 200 |

3 | Monogon | 196 |

4 | vovuh | 189 |

5 | Um_nik | 186 |

6 | pikmike | 185 |

7 | antontrygubO_o | 184 |

8 | Ashishgup | 181 |

9 | pashka | 169 |

10 | Radewoosh | 167 |

Help needed in the following problem :

There are **N** (1<=N<=200000) line segments (end-point coordinates are positive integers less than **1e9**). The task is to merge the line segments that are * overlapping* and finally print the coordinates of all the merged line-segments.

Sample Test Case

N = 4

Line segments:

[(1,1) (5,1)]

[(4,1) (7,1)]

[(3,3) (9,3)]

[(5,3) (8,3)]

The answer for this test case would be :

[(1,1) (7,1)]

[(3,3) (9,3)]

**My Approach** : Consider each line segment as a vertex and make edges between segments U and V if U and V overlaps. Then, find the connected components. For each connected components, answer can be calculated by taking the min of left coordinates and maximum of right coordinates. But this approach is O(N^2) and will not work for N=200000.

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Nov/30/2020 20:39:30 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|