#P9980. [USACO23DEC] Flight Routes G

    ID: 11321 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DPUSACO2023O2优化

[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 1…N1 \dots N (2≤N≤7502 \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 k≥2k \ge 2 cities a=c1<c2<⋯<ck=ba = c_1 < c_2 < \cdots < c_k = b, such that for all 1≤i<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 N−1N - 1 lines follow. Line ii contains N−iN - 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: 1→21 \rightarrow 2 and 2→32 \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 (1→2→31 \rightarrow 2 \rightarrow 3).

Sample Explanation 2

There are six one-way direct flights: 1→21 \rightarrow 2, 1→41 \rightarrow 4, 1→51 \rightarrow 5, 2→32 \rightarrow 3, 3→53 \rightarrow 5, 4→54 \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 3−43 - 4 satisfy N≤6N \le 6.
  • Test points 5−125 - 12 satisfy N≤100N \le 100.
  • Test points 13−2213 - 22 have no additional constraints.

Translated by ChatGPT 5