Let's do an example.
Problem: You have an [math]N\times N[/math] grid ([math]1 \leq N \leq 10^9[/math]). Each square can either be traversed or is blocked. There are M ([math]1 \leq M \leq 100[/math]) obstacles in the grid, each one shaped like a 1xK or Kx1 strip of grid squares. Each obstacle is specified by two endpoints[math] (A_i, B_i)[/math] and [math](C_i, D_i)[/math], where [math]A_i=C_i[/math] or [math]B_i=D_i[/math]. You are also given a start square (X,Y).
The question is: how many squares are reachable from the start square if you can go left, right, up, and down, and you cannot traverse obstacles?
For example:
[math]N = 4 \quad M = 2 \quad X = 0 \quad Y = 0[/math]
[math] A_1 =1 \quad B_1 = 2 \quad C_1 = 1 \quad D_1 = 3[/math]
[math] A_2 = 1 \quad B_1 = 2 \quad C_1 = 3 \quad D_1 = 2[/math]
corresponds to grid (O is the start square and X are obstacles)
O . . .
. . X X
. . X .
. . X .
and the answer for this grid is 10, because the bottom-right 2x3 area is not accessible.
Solution: If the grid were small, we could just do a BFS from the start square. This is [math]\mathcal{O}(N^2)[/math], which is much too big for [math]N=10^9[/math]. However, we can coordinate compress the grid.
The key idea is that MOST ROWS ARE DUPLICATES. The only time row [math]R[/math] is different than row [math]R+1[/math] is if an obstacle starts or ends on [math]R[/math] or [math]R+1[/math]. But there are only 100 obstacles, so this only happens ~100 times. Once we've identified these interesting rows, we know that all the other rows are duplicates of them, so we can compress the grid down into ~100 interesting rows. The same applies for columns. Once we've compressed the grid down to ~[math]100\times 100[/math], we can run the DFS. Then we "blow the grid back up" to get the answer.
Let's be concrete: The interesting rows are 0 (top), [math]R-1[/math] (bottom), [math]A_i-1, A_i, A_i+1[/math] (rows around obstacle start), [math]C_i-1, C_i, C_i+1[/math] (rows around obstacle end). There are at most 602 rows in that list. Sort them from low to high. The gaps are going to be compressed away. For each of the 602 rows, write down the size of the gap below it (this is how many rows it represents, which we need to blow back up the grid).
Do the same thing for the columns. Now we have a [math]602\times 602[/math] graph (actually, smaller). Run BFS on that. Each visited square [math](R,C)[/math] counts (# of rows represented by [math]R[/math])[math]\times[/math](# of columns represented by [math]C[/math]) times. Add up the value for each cell we reached, and that is your answer.