Comparing Answers
Time limit10sMemory limit128 MB
Given an adjacency matrix with edge counts, verify whether a provided matrix correctly gives the number of length-2 paths between every ordered pair (essentially checking a matrix multiplication), for large n up to 1000 requiring fast I/O.
- Level
Medium4 of 10
- Topics
- Matrix, Brute force, Implementation
- Solved
- No attempts yet
Problem
In a place in Southwestern Europe, the name of which I do not wish to recall, not long ago there were cities connected by one-way roads, possibly with more than one road connecting a city to another, or even a road from a city to itself. As a homework assignment for your geography class, you need to compute the number of paths of length exactly two between each ordered pair of cities. However, you have been too busy celebrating the Spanish victory in the World Cup, so now you are copying the answers from your friend. Before handing in your homework, you would like to make sure his answers are correct.
Input
The input consists of several test cases, separated by single blank lines. Each test case begins with a line containing the integer (). The following lines contain elements each; element of line is the number of roads from city to city (an integer between and , inclusive). After that come more lines, again with elements each; element of line is your friend's answer for the number of length-2 paths from city to city , an integer between and , inclusive.
The test cases finish with a line containing only the number zero (also preceded by a blank line).
Note: the input file is large; use fast I/O routines.
Output
For each test case, output a single line. The line should contain YES if your friend's answers for that assignment are all correct, and NO otherwise.