Pick-Up Sticks - 3 Points
Now it's time for some fun. We're going to play Pick-Up sticks. It
works as follows:
A number of sticks will be randomly thrown on the ground, and then
you can remove them one-by-one (hopefully) without moving any other sticks.
One way to think about solving this, is to be smart enough to see what
sticks are "connected." So, you'll be given the locations of the end points
of the sticks, then be asked about sets of 2 sticks. Your job is to determine
if the two sticks in question are connected. Note that connected means
this: if a and b are connected, then there is some sequence of touching
stick from a to b, so for example there exists a c such that a touches c
and c touches b.
Input Format
Your input will contain 3 types of input.
First, you'll be given a single number, this represents the number of
sticks in play. (It will be between 1 and 10, inclusive.)
Second, you'll be given n-sets of end points, describing (in order)
each sticks end points.
Finally, you'll be asked about pairs of sticks, and you should report
on whether or not they touch.
A 0 0 will indicate the end of the pairs.
The input file will be called jin15.txt.
Output Format
For each set in question, you should output the following:
If they are connected:
Yes, stick A is connected to stick B.
If not:
No, stick A is not connected to stick B.
(Note that a stick is considered connected with itself.)
Example
Input
7
1 6 3 3
4 6 4 9
4 5 6 7
1 4 3 5
3 5 5 5
5 2 6 3
5 4 7 2
1 4
1 6
3 3
6 7
2 3
1 3
0 0
Output
Yes, stick 1 is connected to stick 4.
No, stick 1 is not connected to stick 6.
Yes, stick 3 is connected to stick 3.
Yes, stick 6 is connected to stick 7.
No, stick 2 is not connected to stick 3.
Yes, stick 1 is connected to stick 3.