Polish version    English version  
  About Olympic -> Problems -> V OI 1997/1998


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
V Olimpiada Informatyczna 1997/1998

Task: SIE
Author: Piotr Chrz±stowski-Wachtel
Road net

II stage contest  

A diskette was enclosed to a road map. The diskette contains the table of the shortest ways (distances) between each pair of towns on the map. All the roads are two-way. The location of towns on the map has the following interesting property: if the length of the shortest way from town A to town B equals the sum of the lengths of the shortest ways from A to C and C to B then town C lies on (certain) shortest way from A to B . We say that towns A and B are neighbouring towns if there is no town C such that the length of the shortest way from A to B equals the sum of the lengths of the shortest ways from A to C and C to B. Find all the pairs of neighbouring towns.

Example

For the table of distances:
  A B C
A 0 1 2
B 1 0 3
C 2 0 3
the neighbouring towns are A, B and A, C.

Task

Write a program that:

  • reads the table of distances from the text file SIE.IN;
  • finds all the pairs of neighbouring towns;
  • writes the result to the text file SIE.OUT.

Input

In the first line of the text file SIE.IN there is an integer n, 1<=n<200, which equals the number of towns on the map. Towns are numbered from 1 to n.
The table of distances is written in the following n lines of the file SIE.IN. In the (i+1)-st line, 1<=i<=n, there are n non-negative integers not greater than 200, separated by single spaces. The j-th integer is the distance between towns i and j.

Output

Your program should write all the pairs of the neighbouring towns (i.e. their numbers) to the text file SIE.OUT. There should be one pair in each line. Each pair can appear only once. The numbers in each pair should be given in increasing order. Pairs should be ordered so that if the pair (a,b) precedes the pair (c,d) then a < c or (a=c i b < d).

Example

For the text file SIE.IN:

3
0 1 2
1 0 3
2 3 0

the correct answer is the output file SIE.OUT:

1 2
1 3




Print friendly version