## CCC '07 S4 - Waterpark

View as PDF

Points: 7
Time limit: 1.0s
Memory limit: 256M

Problem types
##### Canadian Computing Competition: 2007 Stage 1, Senior #4

The local waterpark has a great slide complex, with many paths crisscrossing down the hill. There is one start point and one end point, but at various points one can turn and take different paths. Walter and Wanda are wondering exactly how many different ways there are to go down the slide. Can you solve their problem?

More precisely, there are marked points (including the start at and the end at ) where the paths down the hill may split or merge. All paths move down the hill to higher numbered positions; some paths will actually cross over others without meeting but we don't have to worry about that. We won't worry about the collisions between sliders that can happen either. Our problem is simply to determine the number of different sequences of marked points we can follow down the hill.

For example, at one small waterpark, there are 4 points with direct slides from to points and ; from to and ; and from to . There are 3 ways down the hill. You can check this by seeing that we can go , or .

(Here is a hint: think about starting at the bottom of the slide.)

#### Input Specification

Input begins with a single integer (), on a line by itself, indicating the number of marked points. The next lines contain point pairs of the form x y, where . For example, 1234 8765 indicates a direct slide from point 1234 to point 8765. The last line of input will be indicated by point pair 0 0.

#### Output Specification

The output is an integer, which is the number of different paths from point to point . You can assume that the number of paths will be less than . It is possible that there is no path from point to point , in which case the number of paths is .

#### Sample Input

4
1 2
1 4
2 3
2 4
3 4
0 0

#### Output for Sample Input

3

• commented on June 30, 2024, 11:16 p.m.

I implemented an inefficient topological sort dp algorithm, and ..... it worked?

Wow.

• commented on Dec. 29, 2022, 1:51 a.m.

This is truly the exact moment Walter White became Heisenberg.

• commented on Dec. 3, 2021, 3:17 p.m. edit 3

I did for testing the following graph:

5
1 2
1 3
1 4
4 3
3 5
2 5
0 0

In this test, there should be 3 paths: (1-2-5), (1-3-5), (1-4-3-5). But the solution of the official CCC, link, gives 2 paths. Maybe I didn't understand the goal of the problem...

• commented on Dec. 3, 2021, 4:49 p.m.

point pairs of the form x y, where .

• commented on Dec. 3, 2021, 7:53 p.m.

you are correct. It seems I misread it. thank you for clearing my doubt.

• commented on Nov. 11, 2017, 3:14 a.m.

My DFS implementation TLEs. Any suggestions?

• commented on Nov. 11, 2017, 1:49 p.m.

Brute force dfs TLEs, try using a different approach. DP is one of the problem types here.

• commented on Aug. 30, 2016, 2:29 p.m.

My code wont run on Dmoj. Works on some compilers only.

• commented on Aug. 30, 2016, 2:46 p.m.

Check the status code help page for some details about the failed initializing error you're getting. Put simply, you're declaring a integer array which would occupy around 381mb of memory.

The memory limit for this problem is 64mb.

• commented on Aug. 30, 2016, 4:50 p.m. edit 2

Is it a coincidence that the example does the exact same thing as his submission?