#P9980. [USACO23DEC] Flight Routes G

[USACO23DEC] Flight Routes G

Problem Description

Bessie recently found out that her favorite rock artist, Elsie Swift, is performing her newest “Eras Tour” concert. Unfortunately, the tickets sold out too quickly, so Bessie is considering flying to another city to attend the concert. The “Eras Tour” will be held in NN cities numbered 1N1 \dots N (2N7502 \le N \le 750). For each pair of cities (i,j)(i, j) with i<ji < j, there may exist a one-way direct flight from ii to jj.

A route from city aa to city bb is a sequence of k2k \ge 2 cities a=c1<c2<<ck=ba = c_1 < c_2 < \cdots < c_k = b, such that for all 1i<k1 \le i < k, there is a one-way direct flight from city cic_i to city ci+1c_{i+1}. For every pair of cities (i,j)(i, j) with i<ji < j, you are given the parity of the number of routes between them (00 means even, 11 means odd).

While planning her travel itinerary, Bessie got distracted. Now she wants to know how many pairs of cities have a one-way direct flight. It can be proven that the answer is unique.

Input Format

The first line contains an integer NN.

The next N1N - 1 lines follow. Line ii contains NiN - i integers. The jj-th integer on line ii represents the parity of the number of routes from city ii to city i+ji + j.

Output Format

Output the number of city pairs that have a one-way direct flight.

3
11
1
2
5
1111
101
01
1
6

Hint

Sample Explanation 1

There are two one-way direct flights: 121 \rightarrow 2 and 232 \rightarrow 3. There is one route between cities 1,21,2 and one route between cities 2,32,3, each consisting of exactly one one-way direct flight. There is also one route between cities 1,31,3 (1231 \rightarrow 2 \rightarrow 3).

Sample Explanation 2

There are six one-way direct flights: 121 \rightarrow 2, 141 \rightarrow 4, 151 \rightarrow 5, 232 \rightarrow 3, 353 \rightarrow 5, 454 \rightarrow 5. This leads to the following numbers of routes:

From \ To 1 2 3 4 5
1 0 1 1 1 3
2 0 0 1
3 0
4
5 0

This matches the input.

Test Point Properties

  • Test points 343 - 4 satisfy N6N \le 6.
  • Test points 5125 - 12 satisfy N100N \le 100.
  • Test points 132213 - 22 have no additional constraints.

Translated by ChatGPT 5