2285 - Traveling Salesman 2285 - Traveling Salesman 2285 - Traveling Salesman

Statistics Sub: 79 | AC: 39 | AC%: 49,37 | Score: 2,74
Created by 2006 Nordic Collegiate Programming Contest
Added by ralcolea (2013-03-20)
Limits
Total Time: 2000 MS |Memory: 62 MB | Output: 64 MB | Size: 14 KB
Enabled languages
Available in

Description

Long before the days of international trade treaties, a salesman would need to pay taxes at every border crossed. So your task is to find the minimum number of borders that need to be crossed when traveling between two countries. We model the surface of Earth as a set of polygons in three dimensions forming a closed convex 3D shape, where each polygon corresponds to one country. You are not allowed to cross at points where more than two countries meet.


Long before the days of international trade treaties, a salesman would need to pay taxes at every border crossed. So your task is to find the minimum number of borders that need to be crossed when traveling between two countries. We model the surface of Earth as a set of polygons in three dimensions forming a closed convex 3D shape, where each polygon corresponds to one country. You are not allowed to cross at points where more than two countries meet.


Long before the days of international trade treaties, a salesman would need to pay taxes at every border crossed. So your task is to find the minimum number of borders that need to be crossed when traveling between two countries. We model the surface of Earth as a set of polygons in three dimensions forming a closed convex 3D shape, where each polygon corresponds to one country. You are not allowed to cross at points where more than two countries meet.


Input specification

Each test case consists of a line containing c, the number of countries (4 <= c <= 6000), followed by c lines containing the integers n x1 y1 z1 . . . xn yn zn, describing (in order) the n corners of a closed polygon (3 <= n <= 20). Then follows a line with one integer m (0 < m <= 50), and then m lines with queries ca cb, where ca and cb are country numbers (starting with 1). No point will be on the line between two connected points, and −10^6 <= x, y, z <= 10^6 for all points. No two non-adjacent edges of a country share a common point. The input is terminated by a case where c = 0, which should not be processed.
Each test case consists of a line containing c, the number of countries (4 <= c <= 6000), followed by c lines containing the integers n x1 y1 z1 . . . xn yn zn, describing (in order) the n corners of a closed polygon (3 <= n <= 20). Then follows a line with one integer m (0 < m <= 50), and then m lines with queries ca cb, where ca and cb are country numbers (starting with 1). No point will be on the line between two connected points, and −10^6 <= x, y, z <= 10^6 for all points. No two non-adjacent edges of a country share a common point. The input is terminated by a case where c = 0, which should not be processed.
Each test case consists of a line containing c, the number of countries (4 <= c <= 6000), followed by c lines containing the integers n x1 y1 z1 . . . xn yn zn, describing (in order) the n corners of a closed polygon (3 <= n <= 20). Then follows a line with one integer m (0 < m <= 50), and then m lines with queries ca cb, where ca and cb are country numbers (starting with 1). No point will be on the line between two connected points, and −10^6 <= x, y, z <= 10^6 for all points. No two non-adjacent edges of a country share a common point. The input is terminated by a case where c = 0, which should not be processed.

Output specification

For each query, output the number of borders you must cross to go from ca to cb.
For each query, output the number of borders you must cross to go from ca to cb.
Each test case consists of a line containing c, the number of countries (4 <= c <= 6000), followed by c lines containing the integers n x1 y1 z1 . . . xn yn zn, describing (in order) the n corners of a closed polygon (3 <= n <= 20). Then follows a line with one integer m (0 < m <= 50), and then m lines with queries ca cb, where ca and cb are country numbers (starting with 1). No point will be on the line between two connected points, and −10^6 <= x, y, z <= 10^6 for all points. No two non-adjacent edges of a country share a common point. The input is terminated by a case where c = 0, which should not be processed.

Sample input

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

Sample output

2
1

Hint(s)

http://coj.uci.cu/24h/
http://coj.uci.cu/24h/
http://coj.uci.cu/24h/

Recommendation

We have carefully selected several similar problems: 3379 | 1873 | 2824 | 3166 | 3954 | 1946