Olympiad Preparation

Mathematical and Informatics Olympiad Preparation

Graph theory is the heart of the combinatorics problems of the mathematical olympiads and the core of the tasks of the informatics olympiads. The masterclass supplies the theory those problems assume; here is how, and how to train the rest.

The two olympiad paths

The International Mathematical Olympiad (IMO) has been held every year since 1959 and now brings together teams of six from more than a hundred countries. Its problems come from four areas: algebra, combinatorics, geometry, and number theory. Each contestant sits two papers of three problems, four and a half hours each, and every problem asks for a proof, marked out of seven. Graph theory is the heart of the combinatorics area: a problem about people who know each other, cities joined by roads, or points joined by coloured segments is a problem about a graph, and the theorems it rests on are the ones in the units. Countries select their teams through national olympiads, usually over several rounds, so the way to the IMO leads through the olympiad of your own country. The European Girls' Mathematical Olympiad (EGMO), held since 2012 with the same format and teams of four, is reached the same way, and many countries outside Europe send guest teams. University students have their own competitions: the William Lowell Putnam Mathematical Competition, held on the first Saturday of December since 1938 for undergraduates in the United States and Canada, whose problems and solutions since 1985 are collected in Kiran Kedlaya's archive, and the International Mathematics Competition for University Students (IMC), held every summer since 1994. Graph theory appears in both.

The International Olympiad in Informatics (IOI) has been held every year since 1989 and takes teams of four from more than ninety countries. An IOI task is a program: the contestant reads a problem, writes code, and is judged on hidden tests, with partial scores for solutions that are correct but too slow. There are two competition days with three tasks each and five hours per day. Graph algorithms are the core of the syllabus. Shortest paths, spanning trees, trees and their diameters, bipartite matching, and flows appear in most years, and a task that looks like a puzzle about cities, cables, or animals in a zoo is nearly always a graph in disguise. The route to the IOI leads through the national informatics olympiad and, in many regions, a regional one such as the Baltic, Central European, or Asia-Pacific olympiad.

A word on what the masterclass does and does not do for each path. It teaches the theory the problems assume and the proofs behind the algorithms, with their hypotheses: that a tree on n vertices has n minus 1 edges and why, that Dijkstra's algorithm needs non-negative weights, that Hall's condition must hold for every subset and not only for single vertices. An IMO contestant needs exactly these statements and the habit of proving things; an IOI contestant needs them to adapt an algorithm to a task that does not name it. What the masterclass does not teach is speed and code. Problem-solving speed under time pressure comes from past problems, and programming comes from a programming resource and a judge that runs your code against tests. Both must be practised alongside the units, and the second half of this page is about how.

Which units cover which topics

The combinatorics problems of the IMO, the EGMO, and the national olympiads that involve graphs draw on the areas in the table. Nothing in them needs calculus.

Syllabus areaWhat it includesUnits
Degrees and countingThe handshake lemma, double counting, the pigeonhole principle, the extremal principle (a longest path, a vertex of largest degree), induction on vertices or edges Unit 1
Paths and connectivityWalks, paths, and cycles, connected components, distance and diameter, bipartite graphs and the odd cycle characterization, breadth-first search, shortest paths Unit 2
Euler trails and Hamilton cyclesEuler's theorem on tours and its open version, Hierholzer's splicing argument, Dirac's and Ore's theorems, why no such theorem exists for Hamilton cycles Unit 3
TreesThe equivalent characterizations of a tree, leaves, spanning trees, Cayley's formula and the Prüfer code, minimum spanning trees Unit 4
MatchingsAlternating and augmenting paths, Hall's theorem with its deficiency version, Kőnig's theorem, systems of distinct representatives, stable matchings Unit 5
Planar graphsEuler's formula and the bounds e ≤ 3v − 6 and e ≤ 2v − 4, why K5 and K3,3 are not planar, the five Platonic solids, Kuratowski's theorem Unit 6
ColouringThe chromatic number, the greedy bound, Brooks's theorem, triangle-free graphs with large chromatic number, the five colour theorem, edge colouring and Vizing's theorem Unit 7
Connectivity and flowsMenger's theorem, the max-flow min-cut theorem, integrality, Kőnig's theorem and Hall's theorem recovered from flows Unit 9
Extremal countingMantel's theorem and Turán's theorem, the Turán graph, counting cherries and the Kővári, Sós, and Turán theorem, the Erdős and Stone theorem Unit 10
The probabilistic methodExpectation and its linearity, the first moment method, the alteration method, graphs with large girth and chromatic number Unit 11
Ramsey's theoremThe party problem, R(s, t) and the Erdős and Szekeres recursion, R(3, 3) = 6 and R(3, 3, 3) = 17, the known small Ramsey numbers Unit 13
Colourings of the integersSchur's theorem from Ramsey's theorem, van der Waerden's theorem and W(2, 3) = 9, colour focusing Unit 15

Units 1 to 7 (in the Foundation masterclass) cover what the first rounds of a national olympiad ask of graph theory: degrees and double counting, paths and bipartite graphs, Euler trails, trees, Hall's theorem, Euler's formula, and colouring, with Unit 1 teaching what a proof is and how induction, contradiction, and the extremal principle are written down. Units 9 to 11 (in the Advanced masterclass) add flows and Menger's theorem, Turán's theorem, and the probabilistic method, which the later rounds and the IMO itself use. Units 13 and 15 (in Advanced + Ramsey Theory) add Ramsey's theorem and the theorems of Schur and van der Waerden, which appear at the IMO every few years in disguise. Units 8, 12, 14, and 16, on real networks, the eigenvalues of graphs, random colourings, and the diagonal Ramsey numbers today, lie outside the olympiad syllabus; they show where the subject goes after it. Every unit shows its arguments step by step on a drawn graph, and the Key Theorems page collects the statements you need to know by heart.

For the informatics olympiads the same units matter in a different order. The table below lists the standard algorithms, the unit that proves each, and what must come from a programming resource, because the masterclass teaches no programming language and no data structures beyond the adjacency matrix and the adjacency list.

IOI topicWhat the unit provesWhat to add from a programming resourceUnit
Breadth-first search and shortest pathsBreadth-first search and its layers, Dijkstra's algorithm with the invariant proof, why negative weights break it, depth-first searchThe queue, the adjacency list, the binary heap for Dijkstra's priority queue Unit 2
Trees and spanning treesWhy a tree on n vertices has n − 1 edges, the diameter of a tree, Kruskal's and Prim's algorithms with the cut propertyUnion-find for Kruskal's algorithm, rooting a tree and computing depths, lowest common ancestors Unit 4
Bipartite matchingAugmenting paths and Berge's theorem, Hall's theorem, Kőnig's theorem, the Gale and Shapley algorithmThe augmenting path implementation (the Hungarian method in its simplest form, or matching through a flow) Unit 5
Maximum flow and minimum cutResidual networks and augmenting paths, the max-flow min-cut theorem, the Ford and Fulkerson method, integrality, Menger's theoremEdmonds and Karp or Dinic as code, modelling a task as a flow network Unit 9
Euler toursEuler's theorem on tours and Hierholzer's algorithm, the open version with two odd verticesA stack-based implementation of Hierholzer's algorithm Unit 3

Three IMO problems and the units behind them

The statements below are those of the official English problem sheets at imo-official.org, with the spelling of the originals. No solutions are given here: the point is to see which theorem of which unit the problem rests on, and then to sit down with it.

IMO 1964, Problem 4

Seventeen people correspond by mail with one another, each one with all the rest. In their letters only three different topics are discussed. Each pair of correspondents deals with only one of these topics. Prove that there are at least three people who write to each other about the same topic.

What it needs. This is the statement R(3, 3, 3) ≤ 17 in disguise: the seventeen people are the vertices of K17, the three topics are three edge colours, and a monochromatic triangle is wanted. The pigeonhole argument at one vertex (sixteen edges, three colours, so six of one colour) followed by the party problem on those six does it, and the unit proves that 17 is exact, since the Clebsch colouring of K16 has no monochromatic triangle. See Unit 13.

IMO 1992, Problem 3

Consider nine points in space, no four of which are coplanar. Each pair of points is joined by an edge (that is, a line segment) and each edge is either colored blue or red or left uncolored. Find the smallest value of n such that whenever exactly n edges are colored, the set of colored edges necessarily contains a triangle all of whose edges have the same color.

What it needs. Two theorems meet here. Turán's theorem (in its triangle case, Mantel's theorem) says how many edges a graph on nine vertices can have without a triangle, which gives the uncoloured edges something to do, and R(3, 3) = 6 says that a two-coloured K6 always has a monochromatic triangle. The problem is to combine the two bounds and to find the colouring that shows the answer is exact. See Unit 10, and Unit 13.

IMO 2019, Problem 3

A social network has 2019 users, some pairs of whom are friends. Whenever user A is friends with user B, user B is also friends with user A. Events of the following kind may happen repeatedly, one at a time: three users A, B, and C such that A is friends with both B and C, but B and C are not friends, change their friendship statuses such that B and C are now friends, but A is no longer friends with B, and no longer friends with C. All other friendship statuses are unchanged. Initially, 1010 users have 1009 friends each, and 1009 users have 1010 friends each. Prove that there exists a sequence of such events after which each user is friends with at most one other user.

What it needs. The social network is a graph and the event is an operation on a path of length two. The solution works with degrees (the handshake lemma shows what the operation does to the number of edges), with connected components and whether they stay connected, with the odd cycle characterization of bipartite graphs, and with spanning trees as the structure that is destroyed last. Everything it needs is in the first four units; the difficulty is in choosing the right invariant. See Unit 1, Unit 2, and Unit 4.

The first two problems are theorems of the masterclass with the names removed, and a student who knows R(3, 3, 3) = 17 and Mantel's theorem recognizes them in a minute; the work is then to write the argument out so that every step is justified. The third is the other pattern, and the more common one at the IMO today: no named theorem settles it, and the solution is built from the elementary facts of the first units, degrees, components, odd cycles, and spanning trees, used in a situation they were not stated for. A student who can prove those facts, and who has the reflex to ask what an operation does to the number of edges and to the components, has most of what the problem needs.

Two IOI tasks and the units behind them

IOI tasks are long documents with input formats and subtasks, so we name two rather than quote them; both are listed with their test data on the pages of IOI 2011 and IOI 2013 at ioinformatics.org, and both can be submitted to the judge at oj.uz.

  • Crocodile (IOI 2011, Pattaya). A cave system with chambers and corridors of known length, an exit at several chambers, and a crocodile that blocks one corridor of your choice at every chamber you leave. The task asks for the length of the route that is guaranteed to reach an exit, and the solution is Dijkstra's algorithm run backwards from the exits with one twist: a chamber is settled on the second time it is reached, not the first. A contestant who knows why the plain algorithm is correct, the invariant that a settled vertex has its final distance, sees why the twist works. See Unit 2.
  • Dreaming (IOI 2013, Brisbane). A forest of trees with weighted edges, to be joined into one tree by adding edges, so that the diameter of the result is as small as possible. The task needs the diameter of a tree, the vertex of a tree that minimizes the longest distance to any other vertex (its centre), and an argument about which centres to join and in which order. The facts about trees and their diameters are in the unit; the two-pass computation of a tree's diameter and the sorting of the trees by radius are the programming. See Unit 4.

What to add to the masterclass

The masterclass teaches the theory and checks it with quizzes. It is not a problem-solving program and not a programming program. To do well at an olympiad, add these:

  • Past problems. The official IMO problem archive has every paper since 1959, the EGMO archive every paper since 2012, and the olympiad of your own country publishes its past rounds; the contest collection of the Art of Problem Solving community gathers all of them with discussed solutions. Work on a problem without looking at the solution, for an hour at least. Check your result, then read the official solution even when yours was right, because the official one is usually shorter and shows what the problem committee had in mind.
  • Past tasks and a judge. Every IOI task since 1989 is on ioinformatics.org with its test data, and oj.uz judges your code against those tests as the contest did. The CSES Problem Set has a graph algorithms section that goes from counting components to flows, one algorithm per problem, which is the right order to learn implementation in.
  • A programming resource. For the IOI path, read Antti Laaksonen's Competitive Programmer's Handbook, free as a PDF, next to the units: its chapters on graph traversal, shortest paths, spanning trees, and flows give the code for what the units prove, and its chapters on data structures give the heap and the union-find structure that the units leave out. The USACO Guide is a free, structured alternative with problems attached to each topic.
  • Written proofs. For the IMO path, write every solution out in full, as you would hand it in, and have someone read it: a teacher, a club leader, or a fellow student. Most lost marks at an olympiad are for a step the solver saw and did not write, or for a hypothesis (the graph connected, the degrees even, Hall's condition for every subset) that was needed and not checked.
  • Speed. Once an area is familiar, time yourself: three problems in four and a half hours leaves ninety minutes for each, and the first fifteen of those are for trying the small cases by hand. Graph problems reward the student who draws the graph on four, five, and six vertices and computes the degrees before thinking. For the IOI, time yourself on three tasks in five hours and learn to collect the partial scores of the subtasks you can do before attempting the full solution.
  • Problem books. Two classics without which no olympiad shelf is complete: László Lovász's Combinatorial Problems and Exercises, whose chapters on graphs run from the handshake lemma to Ramsey theory with hints and full solutions in separate sections, and Arthur Engel's Problem-Solving Strategies, whose chapters on colouring proofs, the extremal principle, and the box principle (his name for the pigeonhole principle) are a syllabus in themselves and full of graphs.
  • The theorems, cold. Before a contest, read the Key Theorems page once more and say each statement with its hypotheses without looking.

A study plan

Follow the masterclass at one unit a week. In the same week, solve five to ten past problems on the area of that unit, starting with the first rounds of a national olympiad and moving to IMO shortlist problems only when those feel comfortable; for the IOI path, implement the algorithm of the week from the handbook and solve the CSES problems that use it before the next unit arrives. In the weeks of Units 1, 2, 5, and 7, which carry most of the olympiad graph theory, take longer and solve more. After Unit 7 you have the theory for the first rounds; after Unit 11 you have every graph-theoretic tool the IMO asks for, and after Units 13 and 15 the Ramsey arguments that appear every few years. In the last weeks before your contest, take full past papers under exam conditions, all four areas for the IMO and full competition days for the IOI, and have the written solutions read or the code tested. Our blog article How to prepare for the graph theory problems of the IMO and the IOI goes into more detail, and the topic page Olympiads and competitions lists further articles.

For teachers

A school mathematics club can use the Foundation masterclass as its theory track: the students read the unit of the week at home and take its quiz, and the club meeting is spent on problems from the area of that unit, with the teacher or an older student reading the written solutions. A programming club can do the same with the units on paths, trees, matchings, and Euler tours, and spend its meetings implementing the algorithm of the week and submitting it to a judge. One unit a week for eight weeks covers the graph theory of the first rounds and the algorithms of the national informatics olympiads, and the certificate at the end gives the students something to show for it. Our page For Schools and Teachers describes how the program works with a group of students and how to look at the material before you recommend it.