The 2026–2027 poster puzzle

The Seven Bridges of Königsberg

Can you draw a continuous loop that crosses each of the 7 bridges exactly once, without ever retracing your steps? People in Königsberg tried for years. In 1736, Leonhard Euler took a closer look — and found a surprisingly short way to settle the question.

A2 format · print-ready PDF

Also in Français · Nederlands · Deutsch

The problem

Königsberg, in what was then Prussia (today Kaliningrad, Russia), was built on both banks of the river Pregel. In the middle of the city the river split around two islands: a central island, the Kneiphof, and a second island to the east. Seven bridges joined these four pieces of land:

  • two bridges between the north bank and the central island;
  • two bridges between the central island and the south bank;
  • one bridge between the two islands;
  • one bridge from the eastern island to each bank.
The seven bridges of Königsberg A map of Königsberg: the river Pregel with a north bank (A), a south bank (D), a central island called Kneiphof (B), and an eastern island (C). Seven numbered bridges join them: 1 and 2 join A and B, 3 and 4 join B and D, 5 joins A and C, 6 joins B and C, and 7 joins C and D. 1 2 3 4 5 6 7 A North bank B Kneiphof C Eastern island D South bank

Your goal — meet all three:

  1. Cross all 7 bridges
  2. Each one exactly once
  3. Finish where you started

No swimming, no boats — only the bridges.

Figure 1. Königsberg in 1736: four landmasses joined by seven bridges. Try the stroll yourself, or watch a sample attempt that gets stuck.

Try it above: residents reportedly searched for a stroll that crosses every bridge exactly once and, for the version on our poster, ends where it started. Nobody found one. Not finding a route does not prove that none exists, and this is where Euler came in.

So… is it possible?

No! And you don’t need to try every route to be sure. Here is the trick.

The in-and-out rule. Every time you walk through a piece of land, you arrive on one bridge and leave on another. So the bridges of that land are used in pairs: one in, one out.

If you must end where you started, every piece of land needs an even number of bridges (2, 4, 6…).

Count them:

  • North bank 3 bridges odd 3 = 1 pair + 1 left over
  • Kneiphof 5 bridges odd 5 = 2 pairs + 1 left over
  • Eastern island 3 bridges odd 3 = 1 pair + 1 left over
  • South bank 3 bridges odd 3 = 1 pair + 1 left over

All four have an odd number. One bridge is always left over, so the loop is impossible. Leonhard Euler found this trick in 1736.

Thinking like this — finding a simple rule instead of trying everything — is exactly what the beOI is about.

Danger zone I want to know everything about this problem with graph theory Proofs, theorems and algorithms ahead.

Heads-up — out of scope

This is completely out of scope for the beOI qualification rounds, the quarter-final and the semi-final. You do not need any of it to do well.

If you enjoy this kind of topic, have a look at competitive programming.

Modelling: from map to graph

Euler noticed that almost everything on the map is irrelevant. The shape of the islands, the length of the bridges and the layout of the streets cannot affect the answer. Only one thing matters: which pieces of land each bridge connects.

So discard the map. Replace each landmass by a point, called a vertex, and each bridge by a line between two vertices, called an edge. The result is a graph G = (V, E) with four vertices and seven edges.

The Königsberg bridges as a multigraph Four vertices: A north bank at the top, B central island on the left, C eastern island on the right, D south bank at the bottom. Seven edges: 1 and 2 join A and B, 3 and 4 join B and D, 5 joins A and C, 6 joins B and C, 7 joins C and D. 1 2 3 4 5 6 7 A North bank B Central island C Eastern island D South bank
Figure 2. Königsberg as a graph. Vertices: A north bank, B central island, C eastern island, D south bank. Edges 1–2 join A and B, 3–4 join B and D, 5 joins A and C, 6 joins B and C, 7 joins C and D. Compare with the map in Figure 1: same letters, same bridge numbers.

Some pairs of vertices are joined by two edges: A–B and B–D. A graph that allows such parallel edges is called a multigraph. In this model the puzzle becomes a pure question about G: is there a closed walk that uses every edge exactly once? Such a walk is called an Eulerian circuit. An Eulerian path also uses every edge exactly once, but may end at a different vertex from where it started.

Degrees

The degree deg(v) of a vertex v is the number of edge ends that touch it. Equivalently, it is the number of bridges leaving that landmass.

Degree of each vertex in Figure 2
Vertex Landmass Bridges Degree
A North bank 1, 2, 5 3 (odd)
B Central island 1, 2, 3, 4, 6 5 (odd)
C Eastern island 5, 6, 7 3 (odd)
D South bank 3, 4, 7 3 (odd)
Sum of degrees 14

As a check, use the handshake lemma. Each edge has exactly two ends, and each end adds 1 to the degree of one vertex. So for every graph,

∑v ∈ V deg(v) = 2 |E|,
and here 3 + 5 + 3 + 3 = 14 = 2 × 7.

One consequence: the sum of all degrees is even, so every graph has an even number of odd-degree vertices.

The invariant

Suppose a walk uses every edge exactly once. Look at a vertex v that is neither its start nor its end. Each time the walk arrives at v along one edge, it must leave along a different, unused edge. The edges at v are therefore used in pairs, one in and one out. Because every edge is used, all edges at v are paired, and deg(v) is even.

Only the two endpoints of the walk get one unpaired edge each: the first edge out of the start and the last edge into the end. If the walk is closed, the start and the end are the same vertex, and those two edges also form a pair. The parity of the degree is an invariant that no clever route can avoid.

Euler’s theorem

Let G be a connected multigraph (ignoring vertices with no edges).

  • G has an Eulerian circuit if and only if every vertex has even degree.
  • G has an Eulerian path if and only if it has 0 or 2 vertices of odd degree. With 2, every such path starts at one odd vertex and ends at the other.

The argument above proves the “only if” direction, which is all the puzzle needs. Euler stated the converse without proof. Carl Hierholzer proved it in 1873 by giving a construction.

Königsberg has four vertices of odd degree. That rules out an Eulerian circuit, which needs zero odd vertices. It also rules out an Eulerian path, which allows at most two. So the loop asked for on the poster does not exist, and neither does any route, closed or open, that crosses each bridge exactly once.

Why it matters in informatics

Euler’s theorem replaces a search with a count. You do not need to try any routes, only to count degrees:

from collections import Counter

def euler_kind(edges):
    """Classify a connected multigraph given as a list of edges (u, v)."""
    degree = Counter()
    for u, v in edges:
        degree[u] += 1
        degree[v] += 1
    odd = sum(1 for d in degree.values() if d % 2 == 1)
    if odd == 0:
        return "Eulerian circuit"
    if odd == 2:
        return "Eulerian path"
    return "neither"

koenigsberg = [("A", "B"), ("A", "B"), ("B", "D"), ("B", "D"),
               ("A", "C"), ("B", "C"), ("C", "D")]
print(euler_kind(koenigsberg))  # neither: four odd vertices

This runs in O(V + E) time: one pass over the edges, then one over the vertices. A complete check also verifies that all edges belong to a single connected component, using one breadth-first or depth-first search, which is also O(V + E). A naive search that tries every order of the edges can examine up to E! sequences. That is 7! = 5,040 for Königsberg, but 20! ≈ 2.4 × 1018 for a graph with only 20 edges.

The same idea appears throughout computer science:

  • Hierholzer’s algorithm builds an Eulerian circuit in O(E) time. Follow unused edges until you return to the start. Then, from any vertex on that circuit that still has unused edges, build another circuit and splice it in.
  • The Chinese postman problem asks for the shortest closed walk that uses every edge at least once, as for mail delivery, snow ploughs or street sweepers. On undirected graphs, it is solved in polynomial time. Pair up the odd vertices with a minimum-weight perfect matching, weighted by shortest-path distance. Then walk the shortest path between each matched pair a second time.
  • De Bruijn graphs in genome assembly: DNA sequencers read millions of short fragments, which are cut into overlapping substrings of length k. Each substring becomes a directed edge from its first k − 1 letters to its last k − 1 letters. Rebuilding the genome then becomes a search for an Eulerian path. In directed graphs, the condition is that in-degree equals out-degree at every vertex, except that the start has one extra outgoing edge and the end has one extra incoming edge.
  • The Hamiltonian contrast: change “every edge exactly once” to “every vertex exactly once” and no simple degree test works anymore. Deciding whether a graph has a Hamiltonian path is NP-complete. No polynomial-time algorithm is known, and finding one would prove P = NP.

Exercise

The city builds an eighth bridge. Between which two landmasses could it go so that an Eulerian path exists? List every pair that works, and say where the walk must start and end in each case.

Follow-up: can a single new bridge ever make an Eulerian circuit possible? What is the minimum number of new bridges needed for that?

This is what the olympiad is about

Euler did not solve the puzzle by trying more routes. He found the right model and the right invariant. The Belgian Olympiad in Informatics asks for the same kind of reasoning, then for a program that applies it.

The online qualification rounds run from 1 December 2026 to 28 February 2027. You can take them at school or at home, in Blockly or Python.