Utkarsh in Gardens
Practice
4 (72 votes)
Medium
Problem
61% Success 3890 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Problem Statement
Utkarsh has recently put on some weight. In order to lose weight, he has to run on boundary of gardens.
But he lives in a country where there are no gardens. There are just many bidirectional roads between cities.
Due to the situation, he is going to consider any cycle of length four as a garden. Formally a garden is considered to be a unordered set of 4 roads {r0, r1, r2, r3} where ri and ri+1 mod 4 share a city.

Now he wonders how many distinct gardens are there in this country.


Input format:
The first integer contains N, the number of cities in the country.
It is followed by space separated elements of N*N binary matrix G.
G[i][j] = 1 denotes there is a road between ith city and jth city.
A pair of cities has atmost one road connecting them.
No road connects a city to itself.
G is symmetric.


Output format:
Print the total number of gardens.


Constraints:
1 ≤ N ≤ 2000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
25 votes
Tags:
GraphsAlgorithmsGraph Representation
Points:30
4 votes
Tags:
AlgorithmsDepth First SearchDijkstra's algorithmDynamic ProgrammingGraphsMedium
Points:30
17 votes
Tags:
AlgorithmsGraphsMedium