Presentation is loading. Please wait.

Presentation is loading. Please wait.

Honors Track: Competitive Programming & Problem Solving Layered Graphs Technique Mark Leenen January 6 th.

Similar presentations


Presentation on theme: "Honors Track: Competitive Programming & Problem Solving Layered Graphs Technique Mark Leenen January 6 th."— Presentation transcript:

1 Honors Track: Competitive Programming & Problem Solving Layered Graphs Technique Mark Leenen January 6 th

2 Disclaimer Close to no information Does not match exactly Layered Graphs Technique Custom made Fancy Animations Gluten free Many features

3  Layered Graph Technique Given a graph G = (V, E), in which the edges are dependent on the state of a variable P, where P can have conditions and weights on its transitions,we want a graph C = (V’, E’) that represents G and the states of P, such that we can run any graph algorithm on it.   

4 Layered Graph Technique Very strong technique Another approach to look at solutions to problems Not necessarily the optimal approach –Huge state space

5 Finite Automata aa b b a, b A finite automaton that accepts the language consisting all sequences with at least two a’s a a b b A finite automaton that accepts the language consisting all sequences with an even number of b’s.

6 Finite Automata aa a a b b b b b b even number of b’s two a’s detected A finite automaton (with input symbols a and b) that accepts the language consisting all sequences with at least two a’s and an even number of b’s.

7 Layered Graph Technique Terminology  Edges representing the edges in the original graph G = (V, E) Layer edges  Edges representing the transitions of variable P Transition edges  Since P is allowed to have conditions on its transitions, for any node in the orginal graph, transition edges do not necessarily appear between its corresponding nodes

8 Semi-quasi-pseudocode-ish thing 1. Read input 2. Make L copies of the original graph (L = #layers) 3. Add transition edges 4. Run desired Graph Algo rithm

9 Semi-quasi-pseudocode-ish thing 1. Read input 2. Make L copies of the original graph (L = #layers) 3. Add transition edges 4. Run desired Graph Algo rithm Copying the graph [ a 1, a 2, …, a n, b 1, b 2, …, b n, c 1, c 2, …,c n, d 1, d 2, … abcd… a1a1 b1b1 c1c1 d1d1 … a2a2 … anan a1a1 b1b1 c1c1 d1d1 … a2a2 b2b2 c2c2 d2d2 … …………… anan bnbn cncn ……

10 Semi-quasi-pseudocode-ish thing 1. Read input 2. Make L copies of the original graph (L = #layers) 3. Add transition edges 4. Run desired Graph Algo rithm Directed / Undirected  Layer edges Not relevant for the Layered Graph itself Undirected edges are commonly implemented as bidirectional directed edges  Transition edges Depend on the conditions on the transitions of P

11 Semi-quasi-pseudocode-ish thing 1. Read input 2. Make L copies of the original graph (L = #layers) 3. Add transition edges 4. Run desired Graph Algo rithm Edge representation Adjacency List versus Adjacency Matrix

12 Adjacency lists vs. adjacency matrix 3 3 14 1 5 4 3 2 2 2 3 1 1 2 3 4 5 31245 1 1 1 1 1 1 1 1 Adjacency listsAdjacency matrix Space Time to list all vertices adjacent to u Time to check if (u, v) ∈ E Θ(V + E)Θ(V 2 ) Θ(degree(u))Θ(V) Θ(1) Θ(degree(u))

13 Spoiler Alert

14 EAPC13 F – Fare Dodging Time filler

15 Fare Dodging - Solution  Read inputs n, m, 2 * start C, 2 * end C, s, p, y C Convert to 0 based  For int i = 0 to n Create node α and give it index 2i // No ticket Create node β and give it index 2i + 1 // Has ticket Create edge α  β and give it weight s // Pay for ticket Create edge b  α and give it weight 0 // Throw out ticket  For int j = 0 to m Create edge from node with index 2a j to 2b j // No ticket  Weight: c * (y + d j * p) Create edge from node with index 2a j +1 to 2b j +1 // Has ticket  Weight: d j * p  Dijkstra! Starts at node start on the layer ‘no ticket’ Ends at node end on the layer ‘no ticket’

16 Problems  BAPC2005 Qualifying Round, A – Bancopia  BAPC2014 A – Avoiding The Apocalypse

17 Questions?


Download ppt "Honors Track: Competitive Programming & Problem Solving Layered Graphs Technique Mark Leenen January 6 th."

Similar presentations


Ads by Google