#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 cities numbered (). For each pair of cities with , there may exist a one-way direct flight from to .
A route from city to city is a sequence of cities , such that for all , there is a one-way direct flight from city to city . For every pair of cities with , you are given the parity of the number of routes between them ( means even, 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 .
The next lines follow. Line contains integers. The -th integer on line represents the parity of the number of routes from city to city .
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: and . There is one route between cities and one route between cities , each consisting of exactly one one-way direct flight. There is also one route between cities ().
Sample Explanation 2
There are six one-way direct flights: , , , , , . 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 satisfy .
- Test points satisfy .
- Test points have no additional constraints.
Translated by ChatGPT 5